【发布时间】:2017-02-26 13:33:12
【问题描述】:
信息:以下代码在 foreach 循环中
作品:
indexSheet.Cell("G" + cellIndex).FormulaA1 = "=SUM(A1:A10)";
只有当我直接在 excel 中输入时才有效:
indexSheet.Cell("G" + cellIndex).FormulaA1 = "=FIND(\"erw\";H5)"; // with Property
indexSheet.Cell("G" + cellIndex).SetFormulaA1("=FIND(\"erw\";H5)"); //with Function
indexSheet.Cell("G" + cellIndex).FormulaA1 = $"COUNTIF(H{cellIndex};\"*\"&$C$2&\"*\")*(MAX($G$4:G{cellIndex - 1})+1)";
indexSheet.Cell("B" + cellIndex).FormulaA1 = $"=IF(ROW()-{cellIndex}>MAX(G:G);\"\";HYPERLINK(CONCATENATE(\"#\";(INDEX(H:H;MATCH(ROW()-4;G:G;0)));\"!B{cellIndex}\");(INDEX(H:H;MATCH(ROW()-4;G:G;0)))))";
我已经检查/尝试过:
- 因为stackoverflow中存在类似的情况:如果我的函数的语言与我的excel语言匹配(都是英文)
- 我尝试过更简单的公式是否可以像
SUM()或FIND()那样工作 -->(-SUM 有效,FIND 无效) - 我直接在 excelsheet 中输入了公式(此处可以使用公式)
- 我在 Loop 外部使用硬编码的单元格信息进行了尝试,没有使用“cellindex”变量
- 查看已关闭的 XML 文档
- 公式开头的等号和不带等号
- 我尝试使用 closedXML Vers。 0.76.0 和 0.80.1(最新稳定版)
Excel 向我展示了这一点: Picture1
还有这个: Picture2
图 2 中的链接 XML 日志文件包含有关已删除部分的信息
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<logFileName>error035720_03.xml</logFileName><summary>Errors were detected in file 'C:\Users\XXX\Documents\Output\CodeBook.xlsx'</summary>
<removedRecords>
<removedRecord>Removed Records: Formula from /xl/worksheets/sheet.xml part</removedRecord>
<removedRecord>Removed Records: Formula from /xl/calcChain.xml part (Calculation properties)</removedRecord>
</removedRecords>
</recoveryLog>
【问题讨论】:
标签: c# excel excel-formula formulas closedxml