我正在尝试设置一些条件设置值,但似乎它们没有采用。当我查看 excel 文档时,它们是默认的。
绿色 = 0.2
黄色 = 0.1
它们显示为
绿色 0.8
黄色 0.6
private static void setIcon(Excel.Worksheet excelWorksheet, string cell)
{
try
{
Excel.IconSetCondition cfIconSet = (Excel.IconSetCondition)excelWorksheet.Range[cell, cell].FormatConditions.AddIconSetCondition();
cfIconSet.IconCriteria[1].Icon = Excel.XlIcon.xlIconRedTrafficLight;
cfIconSet.IconCriteria[2].Type = Excel.XlConditionValueTypes.xlConditionValueNumber;
cfIconSet.IconCriteria[2].Icon = Excel.XlIcon.xlIconYellowTrafficLight;
cfIconSet.IconCriteria[2].Value = Convert.ToDouble(yellow);
cfIconSet.IconCriteria[2].Operator = (int)(Excel.XlFormatConditionOperator.xlGreaterEqual);
cfIconSet.IconCriteria[3].Type = Excel.XlConditionValueTypes.xlConditionValueNumber;
cfIconSet.IconCriteria[3].Value = Convert.ToDouble(green);
cfIconSet.IconCriteria[3].Icon = Excel.XlIcon.xlIconGreenTrafficLight;
cfIconSet.IconCriteria[3].Operator = (int)(Excel.XlFormatConditionOperator.xlGreaterEqual);
}
catch (Exception ex)
{
throw new ArgumentException(ex.Message);
}
}