C# 如何在excel中定义颜色比例条件格式

C# 如何在excel中定义颜色比例条件格式,c#,excel,C#,Excel,我正在尝试使用C#在Excel中的一列数据上设置颜色比例条件格式。我已经成功地添加了其他条件格式规则,但我不知道如何设置此规则。 下面是我添加的一条条件规则,该规则有效: Excel.Range Rng = workSheet.get_Range("H2", "J" + ExcelRowcount.ToString()); Excel.FormatConditions rule2 = Rng.FormatConditions; Excel.FormatCondit

我正在尝试使用C#在Excel中的一列数据上设置颜色比例条件格式。我已经成功地添加了其他条件格式规则,但我不知道如何设置此规则。 下面是我添加的一条条件规则,该规则有效:

Excel.Range Rng = workSheet.get_Range("H2", "J" + ExcelRowcount.ToString());                Excel.FormatConditions rule2 = Rng.FormatConditions;

Excel.FormatCondition between = (Excel.FormatCondition)rule2.Add(Microsoft.Office.Interop.Excel.XlFormatConditionType.xlCellValue, Excel.XlFormatConditionOperator.xlBetween, 0.049999, 0.15, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

Excel.Interior interior3 = between.Interior;
interior3.Color = ColorTranslator.ToOle(Color.LavenderBlush);
但现在我正试图将其作为一个颜色比例规则,我不知道如何格式化长excel函数,这就是我到目前为止所拥有的

Excel.Range range = workSheet.get_Range("L2", "L" +ExcelRowcount.ToString());
Excel.FormatConditions rule3 = range.FormatConditions;

Excel.FormatCondition colorscale = (Excel.FormatCondition)rule3.Add(Microsoft.Office.Interop.Excel.XlFormatConditionType.xlColorScale, Excel.XlFormatConditionType.xlColorScale, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
该列中的值是一些计算的结果,并且之前不知道,因此我需要规则从高值到低值进行缩放。
我还不能很好地理解这个
Excel.XlFormatConditionType
的例子,所以如果有人能帮我解决这个问题,那就太好了!
谢谢

我遇到了同样的问题,对我来说,以下是设置色阶的方法:

MySheet = MyBook.Sheets.get_Item(1);

Excel.ColorScale cfColorScale = (Excel.ColorScale)(MySheet.get_Range("B15", "K34").FormatConditions.AddColorScale(3));
cfColorScale.ColorScaleCriteria[1].Type = Excel.XlConditionValueTypes.xlConditionValueLowestValue;
cfColorScale.ColorScaleCriteria[1].FormatColor.Color = 0x000000FF;  // Red

cfColorScale.ColorScaleCriteria[2].Type = Excel.XlConditionValueTypes.xlConditionValuePercentile;
cfColorScale.ColorScaleCriteria[2].Value = 50;
cfColorScale.ColorScaleCriteria[2].FormatColor.Color = 0x00FFCC00;  // yellow

cfColorScale.ColorScaleCriteria[3].Type = Excel.XlConditionValueTypes.xlConditionValueHighestValue;
cfColorScale.ColorScaleCriteria[3].FormatColor.Color = 0x0000FF00;  // green 
我自己对C#还很陌生,还在学习。。。因此,我无法详细说明解决方案,因为我从谷歌代码->

希望有帮助