Skip to content
This repository has been archived by the owner on Apr 18, 2020. It is now read-only.

Data pre-processing #32

Open
robertmarney opened this issue Oct 23, 2019 · 2 comments
Open

Data pre-processing #32

robertmarney opened this issue Oct 23, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@robertmarney
Copy link

In English locales it is common to separate thousands by using a comma ie 1000 -> 1,000, also for readability zeros are replaced with a '-' (see jquery datatables)

If you were to feed either of these numbers into the parser a NaN error would result with warning for end user.

Consider either a global or cell specific (when data type is numeric) processor.

A quick and dirty deals with the global (not ideal as there may be legitimate string uses for ','

function makeXLSXExport(tableId) {
  let table = document.querySelector("#"+tableId);
  let tableT = table.cloneNode(true);;
  tableT.innerHTML = tableT.innerHTML.replace(/,/g,''); //replaces , globally
  tableT.innerHTML = tableT.innerHTML.replace(/>-</g,'><'); //replaces cells only containing - globally
  TableToExcel.convert(tableT);
}
@rohithb
Copy link
Member

rohithb commented Oct 23, 2019

You can format numbers in the excel by using data-num-fmt="#,##0". However, if you add commas in the HTML table cells, it will not be parsed properly. One workaround is to create a column for the display and create another hidden column for exporting to excel.
One thing we can do is, remove the commas from the cell, which is marked as a number. That way, we don't need to create hidden cells for achieving this.

@rohithb rohithb added the enhancement New feature or request label Oct 23, 2019
@robertmarney
Copy link
Author

@rohithb - Yes, I was not clear, I think that is the best course of action, if the user sets the cell format as numeric strip all commas before processing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants