Spread -Export to Excel(need two excel one with formula,one without formula)

Posted by: Shalini89garg on 9 April 2018, 2:29 am EST

    • Post Options:
    • Link

    Posted 9 April 2018, 2:29 am EST

    Hi ,

    Can anyone please help on below issue

    My requirement is that on click of export button i want to generate two excel , one with formula,one without formula.but its generating only one file.

    btnExport() {

    var count = 0;

    let excelIo = new GC.Spread.Excel.IO();

    for (count = 0; count < 2; count++) {

    if (count === 0) {

    var json = this.spread.toJSON({

    includeBindingSource: true,

    rowHeadersAsFrozenColumns: true,

    columnHeadersAsFrozenRows: true,

    ignoreFormula: true,

    ignoreStyle: false

    });

    }

    else {

    var json = this.spread.toJSON({

    includeBindingSource: true,

    ignoreFormula: false,

    ignoreStyle: false

    });

    }

    let sheetsNames = Object.getOwnPropertyNames(json.sheets);

    sheetsNames.forEach(sheetname => {

    const option = {

    allowFilter: true,

    allowSort: true,

    allowResizeRows: true,

    allowResizeColumns: true,

    allowEditObjects: true

    };

    json.sheets[sheetname].protectionOptions = option;

    json.sheets[sheetname].isProtected = false;

            });
            json.highlightInvalidData = false;
            let currentSheet = this.spread.getActiveSheet()
            let currentSheetname = currentSheet.name();
            if (count === 0) {
                currentSheetname = currentSheetname + 'WithHeaders.xlsx';
            } else {
                currentSheetname = currentSheetname + 'WithFormula.xlsx';
            }
            excelIo.save(json, function (blob: any) {
                FileSaver.saveAs(blob, currentSheetname);
            }, function (e: any) {
            });
        }
    }
    
  • Posted 10 April 2018, 11:14 am EST

    Hello,

    You can use the code as follows to export SpreadJS to Excel with two different options.

    
    
            $("#saveExcel").click(function () {
                var serializationOption = {
                    ignoreFormula: false,
                    ignoreStyle: false,
                    columnHeadersAsFrozenRows: true,
                    includeBindingSource: true
                };
    
                var serializationOption1 = {
                    ignoreFormula: true,
                    ignoreStyle: false,
                    columnHeadersAsFrozenRows: true,
                    includeBindingSource: true
                };
                //spread1.fromJSON(json);
                //var activeSheet = spread1.getActiveSheet();
               // activeSheet.clear(1, 0, 10, 10, GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
                //var myjson = spread1.toJSON();
                // here is excel IO API
                window.setTimeout(function () {
                    var json = spread.toJSON(serializationOption1);
                    excelIo.save(json, function (blob) {
                        saveAs(blob, "ExcelWithoutFormula.xlsx");
                    }, function (e) {
                        // process error
                        console.log(e);
                    }, {
    
                    })
                }, 200);
                window.setTimeout(function () {
                    var json = spread.toJSON(serializationOption);
                    excelIo.save(json, function (blob) {
                        saveAs(blob, "ExcelWithFormula.xlsx");
                    }, function (e) {
                        // process error
                        console.log(e);
                    }, {
    
                    })
                }, 200);
            });
    
    

    I hope it helps.

    Thanks,

    Deepak Sharma

Need extra support?

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

Learn More

Forum Channels