Excel file corrupted when exported using client side ExcelIO

Posted by: jonathan.gross on 12 March 2019, 8:02 pm EST

    • Post Options:
    • Link

    Posted 12 March 2019, 8:02 pm EST

    This is the code I’m using to export spreadJS to excel file

    
    	var workbook = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
    	var fileName = "download.xlsx";
            var json = JSON.stringify(workbook.toJSON());
            var excelIO = new GC.Spread.Excel.IO();
            excelIO.save(json, function (blob) {
                saveAs(blob, fileName);
            }, function (e) {
                console.log(e);
            });
    

    After the file is created, when I try to open in in MS Excel I got the following error:

    We found a problem with some content in ‘download.xlsx’. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes.

  • Posted 13 March 2019, 5:27 pm EST

    Hello,

    We are not able to replicate this issue at our end. We tested with online demo which uses the code similar to yours to export the excel file.

    https://www.grapecity.com/en/demos/spread/JS/InspectorSample/

    Could you please check the same and provide us your sample application to debug it further?

    Thanks,

    Deepak Sharma

  • Posted 23 March 2019, 9:20 pm EST

    Hi Deepak!

    After some investigation we found what causes the problem. If we use GC.Spread.Sheets.Print.PrintInfo() to set margin to sheets, then after we try to export to excel the file becomes corrupted. Please see attached demo.

    SetPrintInfoCorruptsExcelFile.html.zip

  • Posted 25 March 2019, 3:32 am EST

    Hi Jonathan,

    Thanks for the sample.

    The issue in the sample was arising because the margin for header and footer was not set. If you would like to have default values for header/footer then you may use Object.assign() method. Please refer to the following code snippet:

    ```

    var sheet = spread.getSheet(i);

    var printInfo = new GC.Spread.Sheets.Print.PrintInfo();

    printInfo.margin(Object.assign(printInfo.margin() ,opts.margin));

    sheet.printInfo(printInfo);

    We have also updated the sample according and attched it for referance. Please refer to it and let us know if you face any further issues.
    
    Regards
    [zip filename="SetPrintInfoCorruptsExcelFile_updated.zip"]https://gccontent.blob.core.windows.net/forum-uploads/file-73d320de-49c8-4e60-bc2f-48f30eecaa15.zip[/zip]
  • Posted 26 March 2019, 5:51 am EST

    Great, thanks!

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels