Get Excel as blob

I have a grid which works great for a demo, but I need to get the XLS as a blob value in JavaScript so I can manipulate it.

This all works...

grid.toolbarClick = function(args) {

if (args['item'].id === 'Grid_excelexport') {

grid.excelExport(null, null, null, true);

}

}


but this syntax doesn't seem to be correct...


grid.excelExportComplete (args) {

// open blob in new window

}


Can you please assist?




3 Replies

JC Joseph Christ Nithin Issack Syncfusion Team July 27, 2022 08:57 PM UTC

Hi Andy,


Greetings from Syncfusion support.


We can get the Blob data from the excel exporting using excelExportComplete event. In below code example, We have pass the true value in the excelExport method in the toolbarClick event then it will be return the blob data in the excelExportComplete event. Please refer the below code example and sample for more information.


 

grid.toolbarClick = (args=> {

  if (args.item.id === 'Grid_excelexport') {

    grid.excelExport(nullfalsenulltrue);

  }

};

grid.excelExportComplete = (args=> {

  args.promise.then((e=> {

    console.log(e.blobData);

  });

};

 

 


Sample link: https://stackblitz.com/edit/wffbzj?file=index.ts,index.html


Help Documentation: https://ej2.syncfusion.com/javascript/documentation/api/grid/#excelexport
                                       https://ej2.syncfusion.com/javascript/documentation/api/grid/#excelexportcomplete


Please get back to us if you need further assistance.


Regards,

Joseph I



AK andy knasinski September 2, 2022 04:04 AM UTC

This worked for me - but when I duplicated for pdf, I get an error 

Unhandled rejection (<[object Object]>, no stack trace)



 grid.toolbarClick = function(args) {

if (args['item'].id === 'Grid_excelexport') {

   grid.excelExport(null, null, null, true);

}

if (args['item'].id === 'Grid_pdfexport') {

   grid.pdfExport(null, null, null, true);

}

if (args['item'].id === 'Grid_csvexport') {

   grid.csvExport(null, null, null, true);

}

}


grid.pdfExportComplete = (args) => {

args.promise.then((e) => {

// console.log(e.blobData);

var reader = new FileReader();

reader.readAsDataURL(e.blobData);

reader.onloadend = function() {

 var base64data = reader.result;

// console.log(base64data);

FileMaker.PerformScriptWithOption ( 'fnc - Export Report PDF ( param )', base64data, 5 );


}

});

};



JC Joseph Christ Nithin Issack Syncfusion Team September 5, 2022 06:26 PM UTC

Hi Andy,


  Thanks for your update.


We can get the Blob data from the PDF exporting using pdfExportComplete event. In below code example, We have pass the true value in the pdfExport method in the toolbarClick event then it will be return the blob data in the pdfExportComplete event. Please refer the below code example and sample for more information.


 

grid.toolbarClick = function (args) {

  if (args.item.id === 'Grid_pdfexport') {

    grid.pdfExport(null, false, null, true);   // We can get the Blob data in the pdfExportComplete

     event while pass true value in the pdfExport method

  }

};

 

grid.pdfExportComplete = function (args) {

  args.promise.then((e) => {

    console.log(e.blobData);

  });

};

 

 


Sample link: https://stackblitz.com/edit/dmlvdr?file=index.js


Help Documentation: https://ej2.syncfusion.com/javascript/documentation/api/grid/#pdfexportcomplete

                                      https://ej2.syncfusion.com/javascript/documentation/api/grid/pdfExportCompleteArgs/


Please get back to us if you need further assistance.


Regards,

Rajapandiyan S


Loader.
Up arrow icon