workbook.SaveAs
Then I get this error:
Unhandled exception at line 1, column 134417 in http://localhost:57478/bundles/MsAjaxJs?v=c42ygB2U07n37m_Sfa8ZbLGVu4Rr2gsBo7MvUEnJeZ81
0x800a138f - JavaScript runtime error: Unable to get property 'PRM_ParserErrorDetails' of undefined or null reference occurred
The same code at one point in time worked :(. Any ideas?
using (ExcelEngine excelEngine = new ExcelEngine())
{
excelEngine.Excel.DefaultVersion = ExcelVersion.Excel2016;
IWorkbook workbook = excelEngine.Excel.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Name = ddlLocations.SelectedItem.Text;
worksheet.ImportDataTable((DataTable)Session["currentEditLocationsTable"], true, 1, 1);
for (int worksheetIndex = 1; worksheetIndex <= 22; worksheetIndex++)
{
worksheet.AutofitColumn(worksheetIndex);
}
IStyle style = workbook.Styles.Add("NewStyle");
style.Color = System.Drawing.Color.Purple;
style.Font.Color = Syncfusion.XlsIO.ExcelKnownColors.White;
style.Font.Bold = true;
style.VerticalAlignment = ExcelVAlign.VAlignCenter;
style.HorizontalAlignment = ExcelHAlign.HAlignLeft;
worksheet.Range["A1:U1"].CellStyle = style;
worksheet.SetRowHeightInPixels(1, 40);
workbook.SaveAs(@"C:\Users\...\Documents\OrgReadiness\Text.xlsx", Response, ExcelDownloadType.Open);
}
It failed during the workbook.SaveAs command.
It turns out I was using this within an AJAX Update Panel. By putting the button that triggered the Export outside of the Update Panel it worked. I am guessing that something in the Syncfusion XlsIo doesn't work well with AJAX.
|
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(this.Button1);
}
|