0

I am using ag-grid in angular 6 version.

I have provided export button to user for exporting ag-grid data into excel. So, on click event of export I am having following code.

onExport() {
  var params = {
            fileName: 'Users',
            allColumns: true
        };
    var content = this.gridOptions.api.getDataAsExcel(params);
    var workbook = XLSX.read(content, {type: 'binary'});
    var xlsxContent = XLSX.write(workbook, {bookType: 'xlsx', type: 'base64'});
    this.myService.download(params, xlsxContent);
}

This is giving me following error.

UserrolesComponent.html:4 ERROR Error: Unrecognized tag: ![CDATA[URId]]|Workbook,false|Worksheet,false|Table,false
at viewWrappedDebugError (core.js:8439)
at callWithDebugContext (core.js:12214)
at Object.debugHandleEvent [as handleEvent] (core.js:11907)
at dispatchEvent (core.js:8561)
at core.js:9005
at HTMLButtonElement.<anonymous> (platform-browser.js:1215)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:4053)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)

what is the issue?

1
  • I just found that ... i don't need extra lines ... just need to call this.gridOptions.api.getDataAsExcel(params); .. solved my issue Commented Jul 13, 2018 at 6:00

2 Answers 2

3

I ran into this issue as well when upgrading to version 17. I was able to solve it while still allowing exporting to xlsx by setting suppressTextAsCDATA in the params to true.

Example:

var params = {
    suppressTextAsCDATA: true
    // ...
};

var content = this.gridOptions.api.getDataAsExcel(params);
var workbook = XLSX.read(content, {type: 'binary'});
var xlsxContent = XLSX.write(workbook, {bookType: 'xlsx', type: 'base64'});
this.myService.download(params, xlsxContent);
Sign up to request clarification or add additional context in comments.

Comments

2

I removed below lines ....

var content = this.gridOptions.api.getDataAsExcel(params);
var workbook = XLSX.read(content, {type: 'binary'});
var xlsxContent = XLSX.write(workbook, {bookType: 'xlsx', type: 'base64'});
this.myService.download(params, xlsxContent);

and kept only ...

this.gridOptions.api.exportDataAsExcel(params);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.