Parser Error when trying to convert Dataset to Excel

The code works fine up to the point where I do this:

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?


4 Replies

AV Abirami Varadharajan Syncfusion Team February 9, 2018 06:24 AM UTC

Hi Ali, 

Thank you for contacting Syncfusion support. 

We request you to share us the below details to replicate the issue and analyze further from our side. 

  1. Total number of records (rows and columns) imported to Excel.
  2. Code snippet used to generate the document along with the stack trace information of the exception raised.

Please refer below online sample for importing dataset to Excel. 

Also refer below documentation to know more about importing data to Excel. 

Regards, 
Abirami. 



AH Ali Husain February 9, 2018 02:25 PM UTC

This is now resolved.  The error stack trace was in the initial post. Here is my code incase anyone needs a good start:

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.



AH Ali Husain February 9, 2018 02:40 PM UTC

Update:

I was able to figure out. The code cant be triggered from anywhere near an Update Panel. I finally moved my export button to the top of the page away from all Update Panels and it worked. Even if I put the button lower on the screen after an update panel gets called I will get the same error.

It would be great to have Syncfusion actually explain why that is doing that and if its a bug or it happens by design. For now I will leave my work around.


AV Abirami Varadharajan Syncfusion Team February 12, 2018 12:31 PM UTC

Hi Ali, 
 
Thank you for updating detailed description of the issue. 
 
Use of buttons on UpdatePanel will not redirect the entire page load. This uses asynchronous post back to control which part of the page to be rendered. The documents will be downloaded after the entire page is loaded on saveAs. To overcome this, you should have configured the controls outside the update panel that may force a full postback to get the download working.  
 
The issue can also be resolved by registering the button used for Export to send full postback on page load. Please refer below code for the same. 
 
 protected void Page_Load(object sender, EventArgs e) 
        { 
            ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page); 
            scriptManager.RegisterPostBackControl(this.Button1); 
        } 


Kindly try and let us know if this helps at your end. 
 
Regards, 
Abirami 


Loader.
Up arrow icon