Hi, while using CSV Export on Grid widget it exports as UTF-8-BOM, but we need UTF-8.
This is how it shows using Notepad++:
Hi, any updates on this issue?
Thank you. Best regards.
Hi Rodrigo,
We noticed that you would like to export data in UTF-8 format, but you are currently receiving it in UTF-8 with BOM (Byte Order Mark). To meet your requirement of exporting in plain UTF-8 format, we can use the saveAsBlob method instead of the save method.
Please refer to the below sample and code snippet for more information.
Code sample :
|
function toolbarClick(args) { if (args.item.id === 'Grid_csvexport') { var Gridexcelexport = grid.csvExport({}, true); Gridexcelexport.then(function (workbook) { const wbook = new ej.excelexport.Workbook(workbook, 'csv'); wbook.saveAsBlob('text/csv', 'utf8').then(function (result) { var blob = result.blobData; var link = document.createElement('a'); link.download = 'Workbook.csv'; link.rel='nofollow' href = window.URL.createObjectURL(blob); document.body.appendChild(link); link.click(); document.body.removeChild(link); }); }); } };
|
Please get back to us, if you need further assistance.
Regards,
Johnson Soundararajan S
Hi Johnson, thanks for your response.
Works fine with the code provided, the code i'm using uses exportProperties wich now don't work any more.
Please check following code:
Still uses comma as separator instead of semi-colon.
Best regards,
Hi Rodrigo,
We noticed that you would like to utilize exportProperties in the CSV export, but it's not functioning as expected. We attempted to meet your requirement for exporting using exportProperties. We can utilize the FileReader to customize the content.
Please refer to the below sample and code snippet for more information.
Code sample :
|
if (args.item.id === 'Grid_csvexport') { var exportProperties = { separator: ';' }; var Gridexcelexport = grid.csvExport(exportProperties, true); Gridexcelexport.then(function (workbook) { const wbook = new ej.excelexport.Workbook(workbook, 'csv'); wbook.saveAsBlob('text/csv', 'utf8').then(function (result) { var blob = result.blobData; // Convert blob to string var reader = new FileReader(); reader.readAsText(blob, 'utf-8'); reader.onload = function () { // Modify CSV content to include custom separator var csvContent = reader.result.replace(/,/g, ';'); // Create a new blob with modified CSV content var modifiedBlob = new Blob([csvContent], { type: 'text/csv' }); // Create download link var link = document.createElement('a'); link.download = 'Workbook.csv'; link.rel='nofollow' href = window.URL.createObjectURL(modifiedBlob); // Trigger download document.body.appendChild(link); link.click(); // Cleanup document.body.removeChild(link); }; }); }); } }; |
Please get back to us, if you need further assistance.
Regards,
Johnson Soundararajan S
Hi Johnson, thank you for your quick response.
I see you're using a Replace function to replace commas to semicolon, wich might works in most cases, in our case some of the columns have commas inside text fields wich will create extra columns on each hit.
Thank you.
Hi Rodrigo,
We have observed that you are interested in using the exportProperties(separator) function in the CSV export, but it is not working as intended. In order to accommodate your request for exporting with a separator of ';', we can include the parameter in the workbook.
Please refer to the below code snippet for more information.
Code sample :
|
if (args.item.id === 'Grid_csvexport') { var Gridexcelexport = grid.csvExport({}, true); Gridexcelexport.then(function (workbook) { const wbook = new ej.excelexport.Workbook(workbook, 'csv', undefined, undefined, ';' ); wbook.saveAsBlob('text/csv', 'utf8').then(function (result) { var blob = result.blobData; var link = document.createElement('a'); link.download = 'Workbook.csv'; link.rel='nofollow' href = window.URL.createObjectURL(blob); document.body.appendChild(link); link.click(); document.body.removeChild(link); }); }); }
|
Please get back to us, if you need further assistance.
Regards,
Johnson Soundararajan S