使用 IRONXL 如何在 Excel 中高亮顯示每隔一行 Jordi Bardia 更新日期:6月 22, 2025 Download IronXL NuGet 下載 DLL 下載 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article Microsoft Excel 提供內建功能,根據使用者的需求來突出顯示行。 要在 Excel 中突出顯示行,可以使用突出顯示儲存格的動作。 在 Excel 中的突出顯示行功能是一種讓文件更有吸引力的簡單方法。 此工具對於顯示資料點之間的差異非常有用。 但是,在 Microsoft Excel 中突出顯示奇數行可能是棘手的,對於初學者來說並不容易。 然而,為替換行著色對您來說可以變得非常容易。 我們會一步一步地解釋。 讓我們開始吧: 選擇您想要格式化的行。 點擊主菜單中的 首頁,然後點擊 作為表格格式化。 從表格對話框中選擇具有替換行著色的表格樣式。 現在,如果想要將著色從行更改為列,選擇表格並從表格樣式選項組中單擊 設計。然後,從下拉菜單中取消選取 帶狀行 框,然後選取 帶狀列 框。 導航至 Excel 中的帶狀列功能 如果您想保留表格佈局,但不需要其功能,您可以將其轉換為數據範圍。 如果您添加彩色行/列並有帶狀,這不會自動複製。 但是,您可以透過使用格式畫筆複製替代格式的行或列來重新創建格式。 使用條件格式應用帶狀行或列 您還可以使用條件格式規則為特定行或列應用不同格式。 以下是我們的做法: 在工作表上,執行以下之一: 如果想在某些儲存格上應用格式,則選擇儲存格或行的範圍。 如果想將格式應用於整個文檔,則按下 Ctrl+A 來選擇整個文檔。 前往 首頁 > 條件格式 > 新規則。 這將開啟格式規則對話框。 設置條件格式的新規則 在 "選擇規則類型" 部分,選擇 "使用公式來決定要格式化的儲存格" 選項。 在 "編輯規則描述" 部分中寫下以下公式以應用顏色至替換行。 =MOD(ROW(),2)=0 要為替換列應用顏色,請輸入此公式:=MOD(COLUMN(),2)=0。 這些公式確定行或列是偶數還是奇數,並相應地應用所需的格式。 新的格式規則對話框 點擊 格式。 在 格式儲存格 框中,點擊 填滿。 選擇一種顏色然後點擊 確定。 您可以在 樣本 下預覽您的選擇並點擊 確定 或選擇其他顏色。 通過實施以下步驟,您將看到替換行被突出顯示。 IronXL: C# Excel 函式庫 IronXL 是一個 .NET 的 Excel 庫,為開發者提供了一組處理 Excel 的工具。 該庫可以用來讀取、寫入和修改 Excel 文件和工作表。 它還可以用來在不同文件格式之間進行轉換,如 XML、JSON、HTML 和 CSV。IronXL 庫是用 C# 編程語言開發的,它是開放源代碼的,這意味著開發者可以自由地在他們的應用中使用它。 IronXL Excel 庫可以在任何需要訪問 Microsoft Office Excel 的 .NET 項目中使用。 開發者可以在項目中使用 IronXL 而無需在他們的電腦上安裝 Office 或設定來自 Microsoft 的開發者許可。 IronXL Excel 庫提供以下功能: 廣泛的函數集,包括數據操作、數據導出、數據導入以及從其他來源導入。 支持 Microsoft Excel 的所有最新版本。 支持 Excel 最流行的文件格式 (.xlsx)。 Support for cell formatting such as text alignment, font size, color, borders, etc. 能控制 Excel 工作簿中單元格的顯示方式(例如網格線)。 我們可以使用 IronXL 來做條件格式。 要使用 IronXL,您必須在 C# 項目中安裝 IronXL 庫。 安裝庫後,您需要添加 IronXL 命名空間。 在程序文件的開頭寫下以下代碼行: using IronXL; using IronXL.Formatting; using IronXL.Formatting.Enums; using IronXL.Styles; using IronXL; using IronXL.Formatting; using IronXL.Formatting.Enums; using IronXL.Styles; Imports IronXL Imports IronXL.Formatting Imports IronXL.Formatting.Enums Imports IronXL.Styles $vbLabelText $csharpLabel 然後,將以下代碼行添加到您的主要函數中: // Load the Excel workbook WorkBook workbook = WorkBook.Load("test.xlsx"); // Access the default worksheet WorkSheet sheet = workbook.DefaultWorkSheet; // Create a specific conditional formatting rule for values less than 8 ConditionalFormattingRule rule = sheet.ConditionalFormatting.CreateConditionalFormattingRule(ComparisonOperator.LessThan, "8"); // Set different style options for the rule rule.FontFormatting.IsBold = true; rule.FontFormatting.FontColor = "#123456"; rule.BorderFormatting.RightBorderColor = "#ffffff"; rule.BorderFormatting.RightBorderType = BorderType.Thick; rule.PatternFormatting.BackgroundColor = "#54bdd9"; rule.PatternFormatting.FillPattern = FillPattern.Diamonds; // Add the formatting rule to a specific region in the worksheet sheet.ConditionalFormatting.AddConditionalFormatting("A3:A8", rule); // Create another conditional formatting rule for values between 7 and 10 ConditionalFormattingRule rule1 = sheet.ConditionalFormatting.CreateConditionalFormattingRule(ComparisonOperator.Between, "7", "10"); // Set additional style options for the new rule rule1.FontFormatting.IsItalic = true; rule1.FontFormatting.UnderlineType = FontUnderlineType.Single; // Add the second formatting rule to another region in the worksheet sheet.ConditionalFormatting.AddConditionalFormatting("A3:A9", rule1); // Save the updated workbook workbook.SaveAs("ApplyConditionalFormatting.xlsx"); // Load the Excel workbook WorkBook workbook = WorkBook.Load("test.xlsx"); // Access the default worksheet WorkSheet sheet = workbook.DefaultWorkSheet; // Create a specific conditional formatting rule for values less than 8 ConditionalFormattingRule rule = sheet.ConditionalFormatting.CreateConditionalFormattingRule(ComparisonOperator.LessThan, "8"); // Set different style options for the rule rule.FontFormatting.IsBold = true; rule.FontFormatting.FontColor = "#123456"; rule.BorderFormatting.RightBorderColor = "#ffffff"; rule.BorderFormatting.RightBorderType = BorderType.Thick; rule.PatternFormatting.BackgroundColor = "#54bdd9"; rule.PatternFormatting.FillPattern = FillPattern.Diamonds; // Add the formatting rule to a specific region in the worksheet sheet.ConditionalFormatting.AddConditionalFormatting("A3:A8", rule); // Create another conditional formatting rule for values between 7 and 10 ConditionalFormattingRule rule1 = sheet.ConditionalFormatting.CreateConditionalFormattingRule(ComparisonOperator.Between, "7", "10"); // Set additional style options for the new rule rule1.FontFormatting.IsItalic = true; rule1.FontFormatting.UnderlineType = FontUnderlineType.Single; // Add the second formatting rule to another region in the worksheet sheet.ConditionalFormatting.AddConditionalFormatting("A3:A9", rule1); // Save the updated workbook workbook.SaveAs("ApplyConditionalFormatting.xlsx"); ' Load the Excel workbook Dim workbook As WorkBook = WorkBook.Load("test.xlsx") ' Access the default worksheet Dim sheet As WorkSheet = workbook.DefaultWorkSheet ' Create a specific conditional formatting rule for values less than 8 Dim rule As ConditionalFormattingRule = sheet.ConditionalFormatting.CreateConditionalFormattingRule(ComparisonOperator.LessThan, "8") ' Set different style options for the rule rule.FontFormatting.IsBold = True rule.FontFormatting.FontColor = "#123456" rule.BorderFormatting.RightBorderColor = "#ffffff" rule.BorderFormatting.RightBorderType = BorderType.Thick rule.PatternFormatting.BackgroundColor = "#54bdd9" rule.PatternFormatting.FillPattern = FillPattern.Diamonds ' Add the formatting rule to a specific region in the worksheet sheet.ConditionalFormatting.AddConditionalFormatting("A3:A8", rule) ' Create another conditional formatting rule for values between 7 and 10 Dim rule1 As ConditionalFormattingRule = sheet.ConditionalFormatting.CreateConditionalFormattingRule(ComparisonOperator.Between, "7", "10") ' Set additional style options for the new rule rule1.FontFormatting.IsItalic = True rule1.FontFormatting.UnderlineType = FontUnderlineType.Single ' Add the second formatting rule to another region in the worksheet sheet.ConditionalFormatting.AddConditionalFormatting("A3:A9", rule1) ' Save the updated workbook workbook.SaveAs("ApplyConditionalFormatting.xlsx") $vbLabelText $csharpLabel 我們可以使用CreateConditionalFormattingRule() 函數來定義條件格式規則。 使用 IronXL 設計字體樣式和邊框樣式非常簡單。 您可以使用行函數格式化行。 並且,在參數中,您將提供要應用格式的行號和格式。 您可以選擇突出顯示每第 n 行。 您可以在我們的條件格式支持代碼示例中看到更多細節。 IronXL 在開發過程中是免費的。 但是,在開發階段會有水印。 您可以在生產環境中免費嘗試它。 可以不需支付或提供卡信息即可激活IronXL 免費試用版。 之後,您可以購買。 有不同的價格方案,您可以根據需要選擇,請訪問此許可頁面以獲取更多信息。 常見問題解答 如何使用内置功能在 Excel 中突出显示每隔一行? 您可以使用 Excel 的“设置格式为表格”功能来突出显示每隔一行。只需选择您想格式化的单元格范围,转到“主页”,点击“设置格式为表格”,并选择具有交替行着色的表格样式。 如何应用条件格式以突出显示 Excel 中的交替行? 要使用条件格式突出显示交替行,选择您的单元格,进入“主页”>“条件格式”>“新建规则”,输入公式 =MOD(ROW(),2)=0。这将对每隔一行应用格式。 使用 .NET Excel 库用于行突出显示有何优势? 使用类似 IronXL 的 .NET Excel 库,开发人员可以以编程方式应用条件格式,包括突出显示每隔一行,无需手动与 Excel 交互。这可以显著提高生产力和自动化重复性任务。 如何在 C# 中自动化 Excel 文件的操作? IronXL 是一个 .NET 库,专为以编程方式读取、写入和修改 Excel 文件而设计。它允许自动化如突出显示行、应用条件格式和在各种 Excel 文件格式之间转换等任务。 我可以在没有 Microsoft Office 的情况下自动化 Excel 的交替行突出显示吗? 是的,使用 IronXL,您可以自动化 Excel 中交替行的突出显示过程而无需安装 Microsoft Office。IronXL 提供以编程方式应用条件格式的方法。 如何在保持格式的同时将 Excel 表格转换回区域? 您可以通过选择表格、进入“表格设计”并选择“转换为区域”将 Excel 表格转换回区域。为了保持格式,您可能需要使用格式刷工具手动再次应用。 有没有使用 .NET Excel 库的经济有效途径? IronXL 提供一个开发免费版本,其中包含水印。对于生产使用,有多种定价方案可供选择,提供了一个经济有效的解决方案来自动化 .NET 应用程序中的 Excel 任务。 如何使用 .NET 库以编程方式应用条件格式? 使用 IronXL,您可以通过加载工作簿、访问所需的工作表、创建条件格式规则、设置必要的样式选项并保存更新后的工作簿来应用条件格式。 由 .NET Excel 库支持的 Excel 文件格式是什么? IronXL 支持多种 Excel 文件格式,包括 .xlsx,并允许在 XML、JSON、HTML 和 CSV 等格式之间进行转换,使其能够适应不同的应用需求。 Jordi Bardia 立即與工程團隊聊天 軟體工程師 Jordi 在 Python、C# 和 C++ 上最得心應手,當他不在 Iron Software 展現技術時,便在做遊戲編程。在分担产品测测试,产品开发和研究的责任时,Jordi 为持续的产品改进增值。他说这种多样化的经验使他受到挑战并保持参与, 而这也是他与 Iron Software 中工作一大乐趣。Jordi 在佛罗里达州迈阿密长大,曾在佛罗里达大学学习计算机科学和统计学。 相關文章 發表日期 10月 27, 2025 如何在 C# 中創建 Excel 樞紐分析表 學習使用 C# Interop 和 IronXL 創建 Excel 中的樞紐分析表,這是一個清晰的分步指南。 閱讀更多 發表日期 10月 27, 2025 如何在 C# 中將 DataGridView 匯出為 Excel 並保留列標題 學習如何在 C# 教程中使用 IronXL library 將 DataGridView 資料匯出為 Excel 同時保留列標題。分步教學。 閱讀更多 發表日期 10月 27, 2025 如何使用 IronXL 的 .NET Core CSV 讀取器 學習使用 IronXL 作為 .NET Core CSV 讀取器的有效方法,提供實用範例。 閱讀更多 如何在 Excel 中移動行在 C#中讀取 CSV 文件:教程
發表日期 10月 27, 2025 如何在 C# 中將 DataGridView 匯出為 Excel 並保留列標題 學習如何在 C# 教程中使用 IronXL library 將 DataGridView 資料匯出為 Excel 同時保留列標題。分步教學。 閱讀更多