Excel 2007 の条件付き書式機能をプログラムで使用したいと考えています。次のシナリオがあります。
私は6列の数字を持っています
A B C D E F
100 25 25 15 20 50
....
if (C1/A1)*100 >= B1
私はそれを赤く染めなければなりません。同じ規則が D1、E1、F1 列に適用されます。
Excel 2007 で条件付き書式設定機能を見ましたが、C# コードでそれを実装する方法についていくつかの指針が必要です。
Excel 2007 の条件付き書式機能をプログラムで使用したいと考えています。次のシナリオがあります。
私は6列の数字を持っています
A B C D E F
100 25 25 15 20 50
....
if (C1/A1)*100 >= B1
私はそれを赤く染めなければなりません。同じ規則が D1、E1、F1 列に適用されます。
Excel 2007 で条件付き書式設定機能を見ましたが、C# コードでそれを実装する方法についていくつかの指針が必要です。
別に言わなかったので、Interop を喜んで使用すると仮定します。Excelで条件付き書式を設定するために使用するものは次のとおりです。Worksheet
という変数ですでに参照されていると想定していますxlWorksheet
。
// Create a FormatCondition and add it to the specified range of cells, using the
// passed-in condition and cell colour
Excel.Range range = xlWorksheet.get_Range("C1", "C1");
Excel.FormatConditions fcs = range.FormatConditions;
Excel.FormatCondition fc = (Excel.FormatCondition)fcs.Add
(Excel.XlFormatConditionType.xlExpression, Type.Missing, "=IF($C$1/$A$1)*100 >= $B$1");
Excel.Interior interior = fc.Interior;
interior.Color = ColorTranslator.ToOle(Color.Red);
interior = null;
fc = null;
fcs = null;
range = null;
意図した使用法を少し推測しましたが、それをいじって数式とセル参照を正しくすることができます。