Import/Export xlsx files as base64

Posted by: guy.g on 22 October 2018, 3:05 am EST

    • Post Options:
    • Link

    Posted 22 October 2018, 3:05 am EST

    Hi, In Wijmo Flexsheet I can import and export excel files using base64.

    
    	flexSheet.load(base64string);
    
    
    
    	var workbook = flexSheet.save();
    	var base64String = workbook.save();
    
    

    Is this possible using SpreadJS as well?

    It seems like in the documentation the only option is using a File object imported using input

    
    var workbook = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
    var excelIO = new GC.Spread.Excel.IO();
    
        function ImportFile() {
            var excelFile = document.getElementById("fileDemo").files[0];
            excelIO.open(excelFile, function (json) {
                var workbookObj = json;
               workbook.fromJSON(workbookObj);
            }, function (e) {
                console.log(e);
            });
        }
    
    
  • Posted 22 October 2018, 10:21 pm EST

    Hello,

    FlexSheet’s load() method expects base64string. However, in SpreadJS workbook.fromJSON() method expects JSON object. So whenever we load Excel file, then ExcelIO converts the Excel to JSON object and it is then displayed in workbook using fromJSON() method.

    Thanks,

    Reeva

  • Posted 25 October 2018, 2:39 am EST

    So, just convert to using a JSON string instead of using base64 if I’m switching from wijmo FlexSheet to using SpreadJS?

  • Posted 25 October 2018, 10:32 pm EST

    Hello,

    Once base64 string is converrted to JSON string and if JSON string follows SpreadJS JSON Schema then you can import json string to Spread using fromJSON method by parsing it as given in documentation link below:-

    http://help.grapecity.com/spread/SpreadSheets11/webframe.html#SpreadJS~GC.Spread.Sheets.Workbook~fromJSON.html

    Hope it helps.

    Thanks,

    Reeva

  • Posted 26 June 2019, 2:18 am EST

    Could you include PDF export?, Excel works fine, but PDF doesn’t

    I’m using:

    Angular 7

    SpreadJS 11.1.0

    Additional I installed npm install @grapecity/spread-sheets-pdf

    My code is a combination of spreadjs doc

    onClickPDF(args) {

    const fileName = ‘download’;

    this.spread.savePDF(function (blob) {

    saveAs(blob, fileName + ‘.pdf’);

    }, function (error) {

    console.log(error);

    }, {

    title: ‘Test Title’,

    author: ‘Test Author’,

    subject: ‘Test Subject’,

    keywords: ‘Test Keywords’,

    creator: ‘test Creator’

    });

    }

  • Posted 26 June 2019, 4:13 pm EST

    Hi Enrique,

    Could you please let us know the exact issue you are facing with the PDF export. The code snippet you shared seems to be fine.

    Also please make sure that npm ‘file-saver’ package is imported into your project before using the saveAs function.

    Regards

  • Posted 23 June 2021, 11:22 pm EST

    Hello , I am just downloading my excel file as pdf format . using spread.savePDF , but showing error like this , “{errorCode: 0, errorMessage: “File read and write exception.”}”, is their any way to resolve this issue ?

  • Posted 25 June 2021, 6:44 am EST

    Hi,

    We are unable to replicate the issue at our end, please check the following sample and let us know if we are missing something to replicate the issue:

    https://codesandbox.io/s/spread-js-starter-forked-8kveb?file=/index.html

    You may also share a fresh sample that replicates the issue for us to investigate.

    Regards

Need extra support?

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

Learn More

Forum Channels