Importing without overwriting data + Importing events

Posted by: daniel on 26 April 2019, 2:17 am EST

    • Post Options:
    • Link

    Posted 26 April 2019, 2:17 am EST

    Hello,

    Two questions to importing Excel spreadsheets into a SpreadJS workbook. I have the basic code working and functional, but I have these questions:

    1. Can I import a file in such a way that it adds the worksheets from the file to the existing workbook, without overwriting the existing content? Right now if I import a file it completely overwrites all content. For example, if I have worksheets A and B in the SpreadJS workbook, and have worksheets C and D in the Excel file - I would like the resulting SpreadJS workbook to have sheets A,B,C, D

    2. What events are fired when files are imported? For example, can I get an event fired for every cell that is imported and has value? We save the SpreadJS data into a database, so it would be very helpful to know what data we are bringing in.

  • Posted 28 April 2019, 9:49 pm EST

    Hi,

    If you would like to merge the imported workbook with the current workbook then you need to explicitly create a worksheet and load data into the worksheet using fromJSON() method and then add the sheet to the current workbook using addSheet() method.

    Please refer to the following code snippet and the attached sample which demonstrates the same:

    excelIo.open(excelFile, function(json) {
                        var workbookObj = json;
                        
                        // copy sheets
                        var sheets = workbookObj.sheets;
                        for(var key in sheets){
                            var sheetJson = sheets[key];
                            var sheet = new GC.Spread.Sheets.Worksheet();
                            sheet.fromJSON(sheetJson);
                            var i = 1;
                            // check if sheet with current sheets's name already exists, if yes, then rename current sheet
                            while(spread.getSheetFromName(sheet.name())){
                                sheet.name(key + i);
                                i++;
                            }
                            spread.addSheet(spread.getSheetCount(), sheet);
                        }
                        // copy styles
                        var styles = workbookObj.namedStyles;
                        for(var i =0; i< styles.length; i++){
                            var style = styles[i];
                            if(!spread.getNamedStyle(style.name)){
                                spread.addNamedStyle(style);
                            }
                        }
    
                    }
    

    >> What events are fired when files are imported?

    No events are fired during the import/export of the sheet.

    Regards

    ExcelIO2.zip

  • Posted 29 April 2019, 2:25 am EST

    Will try your suggested approach. Thank you!

Need extra support?

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

Learn More

Forum Channels