单元格的 SpreadsheetGear 格式条件
SpreadsheetGear Format Conditions to a Cell
在我的 MVC 项目中,我使用 SpreadsheetGear 生成 excel 文档。我有一列针对它的验证规则只允许用户从以下选项中选择 select:A、B、C、D。我需要能够为每个选项设置不同的背景颜色。例如:
- A - Green
- B - Yellow
- C - Orange
- D - Red
当 运行 代码:
时,我遇到了这个错误
Maximum number of FormatConditions already exists.
我的代码如下:
conditions.Add(FormatConditionType.CellValue, FormatConditionOperator.Equal, "A", null).Interior.Color = Color.LightGreen;
conditions.Add(FormatConditionType.CellValue, FormatConditionOperator.Equal, "B", null).Interior.Color = Color.Yellow;
conditions.Add(FormatConditionType.CellValue, FormatConditionOperator.Equal, "C", null).Interior.Color = Color.Orange;
conditions.Add(FormatConditionType.CellValue, FormatConditionOperator.Equal, "D", null).Interior.Color = Color.Red;
似乎 3 是您可以为一个单元格设置的最大格式条件。无论如何有这个限制吗?
您必须使用旧版本的 SpreadsheetGear,因为 SpreadsheetGear 2012 和之前的版本仅支持 Excel 2003 中可用的条件格式功能,其中包括每个限制 3 个 CF 规则细胞。
release of SpreadsheetGear 2017 enhanced support for Conditional Formats to a level that is compatible with the latest versions of Excel, including specifying more than 3 rules in a cell, so it sounds like you just need to upgrade your application to the latest version. Assuming you have a recent / active subscription, you can download SpreadsheetGear 2017 from the Licensed User Downloads 页面。
在我的 MVC 项目中,我使用 SpreadsheetGear 生成 excel 文档。我有一列针对它的验证规则只允许用户从以下选项中选择 select:A、B、C、D。我需要能够为每个选项设置不同的背景颜色。例如:
- A - Green
- B - Yellow
- C - Orange
- D - Red
当 运行 代码:
时,我遇到了这个错误Maximum number of FormatConditions already exists.
我的代码如下:
conditions.Add(FormatConditionType.CellValue, FormatConditionOperator.Equal, "A", null).Interior.Color = Color.LightGreen;
conditions.Add(FormatConditionType.CellValue, FormatConditionOperator.Equal, "B", null).Interior.Color = Color.Yellow;
conditions.Add(FormatConditionType.CellValue, FormatConditionOperator.Equal, "C", null).Interior.Color = Color.Orange;
conditions.Add(FormatConditionType.CellValue, FormatConditionOperator.Equal, "D", null).Interior.Color = Color.Red;
似乎 3 是您可以为一个单元格设置的最大格式条件。无论如何有这个限制吗?
您必须使用旧版本的 SpreadsheetGear,因为 SpreadsheetGear 2012 和之前的版本仅支持 Excel 2003 中可用的条件格式功能,其中包括每个限制 3 个 CF 规则细胞。
release of SpreadsheetGear 2017 enhanced support for Conditional Formats to a level that is compatible with the latest versions of Excel, including specifying more than 3 rules in a cell, so it sounds like you just need to upgrade your application to the latest version. Assuming you have a recent / active subscription, you can download SpreadsheetGear 2017 from the Licensed User Downloads 页面。