我正在使用closedxml将数据表导出到asp.net中的excel。如果我导出少于50k行但在导出更多行时抛出异常,它工作正常。它有31列。我正在将数据表拆分为10000行,然后将数据表添加到单独的工作表中。如果有人帮助我,我将不胜感激。以下是代码。
XLWorkbook wb = new XLWorkbook();
foreach (DataTable dtdiv in splitdt) //to remove any special characters to avoid format exception(the datatable has xml content)
{
foreach (DataRow row in dtdiv.Rows)
{
for (int i = 0; i < dtdiv.Columns.Count; i++)
{
if (dtdiv.Columns[i].DataType == typeof(string))
{
if (row[i] != System.DBNull.Value)
{
row[i] = ReplaceHexadecimalSymbols((string)row[i]);
}
}
}
}
string newString = "report_" + k;
wb.AddWorksheet(dtdiv, newString);
k++;
}
FileStream fs = new FileStream(Server.MapPath("Test.xlsx"), FileMode.Create);
wb.SaveAs(fs);
fs.Close();
我也试过使用以下
Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment;filename=" + (String)Session["MatrixOutputFileName"]);
using (MemoryStream memoryStream = new MemoryStream())
{
wb.SaveAs(memoryStream);
memoryStream.WriteTo(Response.OutputStream);
memoryStream.Close();
}
Response.End();