TableExport icon indicating copy to clipboard operation
TableExport copied to clipboard

How to delete spaces inside a string?

Open visavi opened this issue 6 years ago • 1 comments

In the table there is one field "money" the data in it is written with spaces in the format 123 345 678.00

Is it possible to remove spaces from numbers before exporting?

visavi avatar Nov 29 '18 13:11 visavi

@visavi – The only real way (at the moment) to achieve that sort of gradual, custom formatting in a safe, reliable way is to munge with the export data directly. The exportButtons example and demo are a good starting point.

The basic idea is to save the TableExport instance to a variable then use a prototype method called getExportData to retrieve the structured data. Then, one can manipulate the data as needed before attaching it to a custom export button .

e.g.

// `id` of the HTML table
const tableId = "export-buttons-table";

// formats
const XLSX = TableExport.prototype.CONSTANTS.FORMAT.XLSX;

// TableExport instance
const instance = new TableExport(document.getElementById(tableId), {
  formats: [XLSX],
  exportButtons: false
});

const exportDataXLSX = instance.getExportData()[tableId][XLSX];

//////////////////////////////////////////////////////
// MODIFY `exportDataXLSX.data` as needed
//////////////////////////////////////////////////////

// `id` of the custom HTML button
const buttonId = "XLSX-button";

// Custom button
document.getElementById(buttonId).addEventListener("click", function(e) {
  instance.export2file(
    exportDataXLSX.data,
    exportDataXLSX.mimeType,
    exportDataXLSX.filename,
    exportDataXLSX.fileExtension
  );
});

clarketm avatar Dec 01 '18 11:12 clarketm