Excel无法识别来自closedXML / c#的公式
信息:以下代码位于foreach循环中
作品:
indexSheet.Cell("G" + cellIndex).FormulaA1 = "=SUM(A1:A10)";
只有当我直接在Excel中input时才有效:
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()
– >( – 工程,FIND不起作用) - 我直接在excelsheet中键入公式(公式在这里工作)
- 我试图从循环以外的一个硬编码的细胞信息,没有“cellindex”variables
- 检出了closedXML文档
- 在公式的开头白色等号,没有它
- 我试着用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>
您不能使用分号( ;
)来分隔closedxml中的参数。 使用逗号( ,
)就像这样:
indexSheet.Cell("G" + cellIndex).FormulaA1 = "=FIND(\"erw\",H5)";
这就是为什么SUM(range)
作品,但FIND(find_text;within_text)
不…