当用户尝试在 excel 表 (.xlsx) 中上传数据时,我收到此错误。它不是一个永久性的问题。我曾经遇到过这个问题,可能一周一次。但今天它经常发生。
private void ExportToExcelOpenOffice(DataTable dataDump)
{
long? empUserId = null;
bool showTeamData = false;
if (this.IsUserEntryValid())
{
if (CurrentUser.Details.UserType == UserType.User)
{
empUserId = CurrentUser.Details.EmployeeUserId;
showTeamData = true;
}
if (dataDump.IsValid(true))
{
// ExcelHelper.ToExcel(dataDump, "ELogger_DataDump.xls", this.Response);
// RichExcelHelper.ToExcel(dataDump, "ELogger_DataDump.xls", this.Response);
using (ExcelPackage pck = new ExcelPackage())
{
ExcelWorksheet ws = pck.Workbook.Worksheets.Add("Page 1");
ws.Cells["A1"].LoadFromDataTable(dataDump, true);
//Write it back to the client
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", "attachment; filename=ELogger_DataDump.xlsx");
Response.BinaryWrite(pck.GetAsByteArray());
Response.Flush();
Response.End();
}
}
else
{
lblMessage.Visible = true;
lblMessage.Text = "No records found.";
}
}
else
{
lblMessage.Visible = true;
lblMessage.Text = this.errorMessage;
}
}