带有图标 Epplus 的条件格式

Conditional Formatting With Icons Epplus

我需要用 Epplus 实现这样的目标。

谁能指导我使用我需要使用的代码。

以下是完全按照您的要求执行的代码,但它适用于三个图标集,您可以根据您的图标进行更改。如果值大于 4,我设置红色箭头,如果值在 1 到 4 之间,我设置黄色箭头,最后,如果值小于 1,我设置绿色。只需将 "AddThreeIconSet" 更改为您的图标。你应该明白这一点。

for (int j = 2; j <= 9; j++) // Loop through columns
{
   for (int i = 3; i <= 12; i++) // Loop through rows
   {
       // gets only the current cell as range
       ExcelRange rng = worksheet.Cells[i, j, i, j]; 
       ExcelAddress address = new ExcelAddress(rng.Address);
       // Get the value of the current cell
       if(Convert.ToDouble(worksheet.Cells[i, j].Value) >= 4.0)
       {
          var v = worksheet.ConditionalFormatting.AddThreeIconSet(address, eExcelconditionalFormatting3IconsSetType.Arrows);
          v.Reverse = true;
          v.Icon1.Type = eExcelConditionalFormattingValueObjectType.Num;
       }
       else if (Convert.ToDouble(workSheet.Cells[i, j].Value) > 1.0 && Convert.ToDouble(workSheet.Cells[i, j].Value) < 4.0)
       {

          var v = worksheet.ConditionalFormatting.AddThreeIconSet(address , eExcelconditionalFormatting3IconsSetType.Arrows);
          v.Icon3.Type = eExcelConditionalFormattingValueObjectType.Num;

       }
       else if (Convert.ToDouble(workSheet.Cells[i, j].Value) < 1.0)
       {
          var v = worksheet.ConditionalFormatting.AddThreeIconSet(address , eExcelconditionalFormatting3IconsSetType.Arrows);
          v.Icon2.Type = eExcelConditionalFormattingValueObjectType.Num;
       }
    }
}