【问题标题】:Conditional Formatting With Icons Epplus带有图标的条件格式 Epplus
【发布时间】:2015-02-05 10:33:41
【问题描述】:

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

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

【问题讨论】:

    标签: epplus epplus-4


    【解决方案1】:

    以下是完全符合您要求的代码,但它适用于三个图标集,您可以根据您的图标对其进行更改。如果值大于 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;
           }
        }
    }
    

    【讨论】:

    • 感谢 sanmis 的帮助。
    • 您也可以使用这个stackoverflow.com/questions/28493050/… 它允许您先在excel中进行任何格式化,将其导入为xml,然后使用它。这样,您可以使用任何类型的条件格式以及任何类型的规则。
    • 我不确定您实际设置颜色的位置?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-08
    • 2015-04-08
    • 1970-01-01
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    相关资源
    最近更新 更多