无法在EPPLUS

时间:2019-10-30 09:10:29

标签: epplus epplus-4

我正在使用template.xltx文件创建新的.xlsx文件。模板文件(Template.xltx)包含表和公式。将公式添加到.xltx文件中,以验证表是否具有数据。

当我尝试在Cell [31,1]上检索最终结果值时,它没有返回计算出的值。而是返回模板中的值。你能帮忙吗?

模板文件:

Template.xltx

EPPLus代码:

FileInfo templateFile=new FileInfo("C:\\Template.xltx");
FileInfo excelFile=new FileInfo("C:\\Result.xlsx");
var package=new ExcelPackage(excelFile,templateFile);
package.Workbook.Worksheets[0].Cells[4, 1].Value = "test12";
package.Workbook.Worksheets[0].Cells[4, 2].Value = "1";
package.Workbook.Worksheets[0].Cells[4, 3].Value = "asfdf";
package.Workbook.Worksheets[0].Cells[4, 4].Value = "a333f";
package.Workbook.Worksheets[0].Cells[21, 1].Value = "test12";
package.Workbook.Worksheets[0].Cells[21, 2].Value = "1";
package.Workbook.Worksheets[0].Cells[21, 3].Value = "asfdf";
package.Workbook.Worksheets[0].Cells[21, 4].Value = "a333f";
ExcelCalculationOption option=new ExcelCalculationOption();
option.AllowCirculareReferences = true;
package.Workbook.Worksheets[0].Calculate(option);
package.Save();
Assert.AreEqual("Success", package.Workbook.Worksheets[0].Cells[31,1].Value);
package.Dispose();

1 个答案:

答案 0 :(得分:0)