IRONSOFTWAREHOME
Excel 条件格式
using IronXL;
using IronXL.Formatting.Enums;
using IronXL.Styles;

WorkBook workBook = WorkBook.Load("sample.xlsx");
WorkSheet workSheet = workBook.DefaultWorkSheet;

// Create conditional formatting rule
var rule = workSheet.ConditionalFormatting.CreateConditionalFormattingRule(ComparisonOperator.LessThan, "8");
// Set style options
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;
// Apply formatting on specified region
workSheet.ConditionalFormatting.AddConditionalFormatting("A3:A8", rule);

// Create conditional formatting rule
var rule1 = workSheet.ConditionalFormatting.CreateConditionalFormattingRule(ComparisonOperator.Between, "7", "10");
// Set style options
rule1.FontFormatting.IsItalic = true;
rule1.FontFormatting.UnderlineType = FontUnderlineType.Single;
// Apply formatting on specified region
workSheet.ConditionalFormatting.AddConditionalFormatting("A3:A9", rule1);

workBook.SaveAs("applyConditionalFormatting.xlsx");
Imports IronXL
Imports IronXL.Formatting.Enums
Imports IronXL.Styles

Dim workBook As WorkBook = WorkBook.Load("sample.xlsx")
Dim workSheet As WorkSheet = workBook.DefaultWorkSheet

' Create conditional formatting rule
Dim rule = workSheet.ConditionalFormatting.CreateConditionalFormattingRule(ComparisonOperator.LessThan, "8")
' Set style options
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
' Apply formatting on specified region
workSheet.ConditionalFormatting.AddConditionalFormatting("A3:A8", rule)

' Create conditional formatting rule
Dim rule1 = workSheet.ConditionalFormatting.CreateConditionalFormattingRule(ComparisonOperator.Between, "7", "10")
' Set style options
rule1.FontFormatting.IsItalic = True
rule1.FontFormatting.UnderlineType = FontUnderlineType.Single
' Apply formatting on specified region
workSheet.ConditionalFormatting.AddConditionalFormatting("A3:A9", rule1)

workBook.SaveAs("applyConditionalFormatting.xlsx")
NuGet Download
PM > Install-Package IronXL.Excel
Excel 条件格式

Excel 条件格式

IronXL 库支持单元格和区域的条件格式设置。 条件格式允许根据逻辑/程序规则更改单元格的样式,例如背景颜色或文本样式。

使用CreateConditionalFormattingRule(string formula)创建基于布尔公式的条件格式规则。 当公式结果为真时,单元格将被高亮显示。 请注意,要计算的公式必须是布尔函数。

具有三个参数的ComparisonOperator.NotBetween作为第一个参数。

使用条件格式,根据单元格的真/假值(由设定的规则确定),以指定的颜色和格式组合突出显示单元格和区域。 这使得我们能够分析数据、检测问题并识别模式和趋势。

学习如何在 C# 中应用条件格式
在 GitHub 上查看

准备开始了吗?

Nuget Downloads 2,280,941版本:2026.10刚刚发布

Key in blue circle

立即获取免费的 30 天试用版密钥。

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronXL
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
您的资料将始终保密。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
深受全球数百万工程师信赖
立即获取您的免费30 天试用密钥。
无需信用卡或创建账户
C# 用于 PDF 的 NuGet 库
通过 NuGet 安装

版本: 2026.10

PM > Install-Package IronXL.Excel
nuget.org/packages/IronXL.Excel/
  1. 在解决方案资源管理器中,右键点击引用,管理 NuGet 包
  2. 选择浏览并搜索“IronXL”
  3. 选择包并安装
C# PDF DLL
下载 DLL

版本: 2026.10

  1. 下载并解压IronXL到你的解决方案目录中的~/Libs等位置
  2. 在Visual Studio解决方案资源管理器中,右键单击引用。选择浏览,“IronXL.dll”

许可证从 $999