Export to Excel :- Show only Headers not Data while Export

Posted by: Shalini89garg on 9 April 2018, 12:18 pm EST

    • Post Options:
    • Link

    Posted 9 April 2018, 12:18 pm EST

    Hi,

    Can anyone please on below requirement.

    While Export to excel ,it should only fetch headers not data.

    Can we set some property to ignoreData.

    var json = this.spread.toJSON({

    includeBindingSource: true,

    rowHeadersAsFrozenColumns: true,

    columnHeadersAsFrozenRows: true,

    ignoreFormula: true,

    ignoreStyle: false

    });

  • Posted 10 April 2018, 11:02 am EST

    Hello,

    You would need another Spread instance to hold the JSON before exporting to Excel and then removing the data from it. You can keep the other spread instance hidden.

    Please refer to the code below:

     $("#saveExcel").click(function () {
                var serializationOption = {
                    ignoreFormula: false,
                    ignoreStyle: false,
                    columnHeadersAsFrozenRows: true,
                    includeBindingSource: true
                };
                var fileName = "export.xlsx";
    
                if (fileName.substr(-5, 5) !== '.xlsx') {
                    fileName += '.xlsx';
                }
    
                var json = spread.toJSON(serializationOption);
                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
                excelIo.save(myjson, function (blob) {
                    saveAs(blob, fileName);
                }, function (e) {
                    // process error
                    console.log(e);
                }, {
    
                });
    
            });
    

    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