TableExport icon indicating copy to clipboard operation
TableExport copied to clipboard

Option to remove commas if cell value will be a number without the commas?

Open nowherenearithaca opened this issue 7 years ago • 3 comments

Was wondering how hard it would be to have the option to remove commas if the value about to be written for a cell is a number without the comma. Otherwise, you need to muck with it on the excel side.

Similarly, replace things like "(123)" with "-123"

nowherenearithaca avatar Sep 19 '18 14:09 nowherenearithaca

ok - it looks like there is a "formatValue" function that is added to the settings object internally, but not currently settable via settings - wonder if just allowing that would work...

nowherenearithaca avatar Sep 19 '18 16:09 nowherenearithaca

that worked - basically, you just replace this line at https://github.com/clarketm/TableExport/blob/a18b72420e5fa179134bd059b73d45f0957092ee/src/stable/js/tableexport.js#L72

with something like

settings.formatValue = settings.formatValue ? settings.formatValue.bind(this, settings.trimWhitespace) : self.formatValue.bind(this, settings.trimWhitespace);

and when you call tableExport, pass your function with parameter formatValue set to a function with a signature like this: formatValue(isTrimWhitespace, string) that does whatever formatting/cleaning you want

nowherenearithaca avatar Sep 19 '18 17:09 nowherenearithaca

@nowherenearithaca – You are correct, formatValue is not configurable via settings (although maybe it should be and I would be open to a PR if you have the bandwidth), but as a slightly less flexible workaround it can be set as a global configuration via mutating the TableExport prototype, which basically essentially changes what self.formatValue points to when it is binded.

e.g.

TableExport.prototype.formatValue = function (isTrimWhitespace, string) {
    return "custom logic here ... "string" will be the data that needs to be formatted"
}
// Run TableExport logic 

clarketm avatar Oct 24 '18 07:10 clarketm