Excel无法识别来自closedXML/c#的公式

4

信息:以下代码在 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)))))";

我已经检查/尝试过:

  1. 因为在stackoverflow上存在一个类似的情况:如果我的函数语言与我的Excel语言匹配(都是英文)
  2. 我尝试使用简单的公式,如SUM()FIND() ->(-SUM有效,FIND无效)
  3. 我直接在Excel工作表中输入公式(此处的公式有效)
  4. 我尝试了循环外面使用硬编码的单元格信息并且没有使用“cellindex”变量
  5. 查看了closedXML文档
  6. 有等号开头和没有等号开头的公式
  7. 我尝试了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>
2个回答

8
您不能在closedxml中使用分号(;)来分隔参数。请使用逗号(,),如下所示:
indexSheet.Cell("G" + cellIndex).FormulaA1 = "=FIND(\"erw\",H5)";

这就是为什么SUM(range)可以使用,而FIND(find_text;within_text)不能使用的原因...


1

在编程中,必须使用逗号(,)来分隔参数。不要像Excel一样使用分号(;)。


1
这个答案与被接受的答案没有任何区别 - 我建议删除它。 - Ike

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接