6

我的网页中有一个由 Epplus 库生成的简单 Excel 文档;但是,当我使用 excel 函数“小计”时,出现以下错误:

Excel 在...中发现无法读取的内容

这是代码:

protected void Page_Load(object sender, EventArgs e)
{
   ExcelPackage pck = new ExcelPackage();
   ExcelWorksheet ws = pck.Workbook.Worksheets.Add("hoja1");

   ws.Cells["A1"].Value = 1;
   ws.Cells["A2"].Value = 2;
   ws.Cells["A3"].Value = 3;
   ws.Cells["A1:A3"].Style.Numberformat.Format = "#,##0";

   ws.Cells["A4"].Formula= "SUBTOTAL(9;A1:A3)";

   Response.Clear();
   Response.AddHeader("content-disposition", 
        string.Format("attachment;filename=\"{0}\"", "Reporte.xlsx"));
   Response.ContentType = 
        "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
   Response.BinaryWrite(pck.GetAsByteArray());
   Response.End();
}

和带有详细信息的 xml 文档:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
   <logFileName>error057400_01.xml</logFileName>
   <summary>
      Se han detectado errores en el archivo "C:\xxxxxx\Content.IE5\MAW7NL0X\Reporte.xlsx"
   </summary>
   <removedRecords summary="Lista de registros eliminados:">
      <removedRecord>
          Registros quitados: Fórmula de /xl/worksheets/sheet1.xml parte
      </removedRecord>
</removedRecords></recoveryLog>

注意:如果我切换到使用以下功能,一切正常。为什么我的小计不起作用?

ws.Cells["A4"].Formula= "SUM(A1:A3)";
4

1 回答 1

19

不确定这是否是问题,但尝试替换“;” 带有“,”:

ws.Cells["A4"].Formula= "SUBTOTAL(9,A1:A3)";

祝你好运。

于 2013-01-26T03:35:46.113 回答