How to read flexsheet saved as zip file to backend

Posted by: chandrasekar_keerthana on 6 January 2020, 7:38 am EST

    • Post Options:
    • Link

    Posted 6 January 2020, 7:38 am EST

    Hi Team,

    I have a requirement to save the flexsheet to DB and retrieve it when the user needs it. It worked fine with JsZip 2.5 but after upgrading to jsZip 3.1, isnipte of modifying all the methods, I’m unable to load the saved sheet back from DB.Below is a snippet of the code used before and after JsZip upgrade.

    with jszip 2.5V

    saveSheetToDB(){

    var zip = new JSZip();

    /// serialize sheet_data.

    zip.file(“sheet_data”, JSON.stringify(records));

                /// c. serialize sheet.
                zip.file("sheet", vm.get("sheet").save().save());
                var zip_data = zip.generate({ type: "uint8array" });
    

    ajax call to save zip_data to DB

    }

    loadSheetFromDB{

    ajax call to DB

    var zip_obj= new JSZip();

    zip_obj.load(response.responseBytes);

    var data=JSON.parse(zip_obj.file(“sheet_data”).asText())

                    /// load wijmo sheet.
                    var base64 = zip_obj.file("sheet").asText();
    	    sheet = new wijmo.grid.sheet.FlexSheet("#id"));
                    /// load workbook.
                   sheet.load(base64);
    

    }

    with jszip 3.1.5V

    saveSheetToDB(){

    var zip = new JSZip();

    /// serialize sheet_data.

    zip.file(“sheet_data”, JSON.stringify(records));

                /// c. serialize sheet.
                zip.file("sheet", vm.get("sheet").saveAsync().saveAsync());
                var zip_data = zip.generateAsync({ type: "uint8array" }).then(function (zip_data){
    

    ajax call to save zip_data to DB

    }

    });

    }

    loadSheetFromDB{

    ajax call to DB

    var zip1= new JSZip();

    zip1.loadAsync(response.responseBytes).then(function(zip_obj){

    zip_obj.file(“sheet_data”).async(“string”)

    .then(function (data) {

                    /// load wijmo sheet.
                    zip_obj.file("sheet").async("string")
                                .then(function (base64) {
    	    var sheet = new wijmo.grid.sheet.FlexSheet("#id"));
                    /// load workbook.
                   sheet.loadAsync(base64);
    

    });

    });

    });

    }

    But the zip_obj.file(“sheet”).async(“string”) method doesn’t return any data. whereas when i look into zip_obj I see that it has a definition for “sheet” as a file. Could you please help me in identifying the problem here.

    Thanks,

    Keerthana

  • Posted 7 January 2020, 1:13 am EST

    Hi Keerthana,

    Since you are using saveAsync method to save the FlexSheet, you will not get the saved Workbook instance and the base64 string directly. To solve this, you will need to handle the onSaved callback.

    Also, in the loadSheetFromDB method, the flexsheet cannot be loaded using the base64 string. You will need to create a Workbook instance and load it using the base64 string. Please refer to the updated sample link below:

    https://stackblitz.com/edit/js-ybaaf3

    Regards,

    Ashwin

Need extra support?

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

Learn More

Forum Channels