如何使用 EPPlus 添加条件格式 Excel 2010
How to add conditional formatting with EPPlus for Excel 2010
我正在使用 Epplus 库向现有 Excel 电子表格添加条件格式,代码如下:
var conditionalFormatting = worksheet.Cells[address].ConditionalFormatting.AddExpression();
conditionalFormatting.Formula = $"=IF(EXACT(A1, \"\"), IF(EXACT(B1, \"\"), TRUE, FALSE), FALSE)";
conditionalFormatting.Style.Fill.BackgroundColor = errorColor;
此代码似乎工作正常,因为当我使用 Excel 2016 打开电子表格时,我可以看到适当的行为。
我的问题
打开与 Excel 2010 相同的电子表格时,我收到此消息:
Excel found unreadable content in 'Spreadsheet.xlsx'. Do you want to recover the contents of this Workbook?
恢复内容:Excel 提示:
Removed Feature: Conditional formatting from /xl/worksheets/sheet1.xml part
这件事发生在其他人身上吗?我认为 EPPlus 库应该可以在 Excel 2007+
下正常工作
有人知道任何解决方法吗?
尝试从 Formula
中删除 =
符号。
conditionalFormatting.Formula = $"IF(EXACT(A1, \"\"), IF(EXACT(B1, \"\"), TRUE, FALSE), FALSE)";
通过添加 =
会导致公式显示为 ==IF(EXACT...
,这是无效的。条件格式的公式不以 =
开头的符号存储。如果这在 Excel 2016 年仍然有效,也许 accepts/ignores 额外的 =
?
我正在使用 Epplus 库向现有 Excel 电子表格添加条件格式,代码如下:
var conditionalFormatting = worksheet.Cells[address].ConditionalFormatting.AddExpression();
conditionalFormatting.Formula = $"=IF(EXACT(A1, \"\"), IF(EXACT(B1, \"\"), TRUE, FALSE), FALSE)";
conditionalFormatting.Style.Fill.BackgroundColor = errorColor;
此代码似乎工作正常,因为当我使用 Excel 2016 打开电子表格时,我可以看到适当的行为。
我的问题
打开与 Excel 2010 相同的电子表格时,我收到此消息:
Excel found unreadable content in 'Spreadsheet.xlsx'. Do you want to recover the contents of this Workbook?
恢复内容:Excel 提示:
Removed Feature: Conditional formatting from /xl/worksheets/sheet1.xml part
这件事发生在其他人身上吗?我认为 EPPlus 库应该可以在 Excel 2007+
下正常工作有人知道任何解决方法吗?
尝试从 Formula
中删除 =
符号。
conditionalFormatting.Formula = $"IF(EXACT(A1, \"\"), IF(EXACT(B1, \"\"), TRUE, FALSE), FALSE)";
通过添加 =
会导致公式显示为 ==IF(EXACT...
,这是无效的。条件格式的公式不以 =
开头的符号存储。如果这在 Excel 2016 年仍然有效,也许 accepts/ignores 额外的 =
?