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");
NuGet Download
PM > Install-Package IronXL.Excel
Excelの条件付き書式

Excelの条件付き書式

IronXLライブラリは、セルや範囲の条件付き書式をサポートしています。 条件付き書式では、論理的/プログラム的なルールに基づいて、セルのスタイル、例えば背景色やテキストのスタイルを変更することができます。

CreateConditionalFormattingRule(string formula) を使用して、ブール式に基づく条件付きフォーマッティングルールを作成します。 式の結果が真の場合、セルが強調されます。 評価するための式は、Boolean関数でなければなりませんことを注意してください。

3つのパラメータを持つCreateConditionalFormattingRule メソッドは、ComparisonOperator.Between とComparisonOperator.NotBetween のみを最初のパラメーターとすることができます。

条件付き書式を使用して、設定されたルールによって決定されたセルの真/偽の値に依存する色と形式の組み合わせでセルや範囲を強調表示します。 これにより、データを分析し、問題を検出し、パターンやトレンドを識別する能力を得られます。

C#で条件付き書式を適用する方法を学ぶ
GitHubで見る

準備はできましたか?

Nuget Downloads 2,362,812バージョン:2026.11リリースされたばかり