sheetjs
sheetjs copied to clipboard
Auto converting string data with all integer to exponential.
While writing string data (example = "121212121212121" -> string of all integer characters) into excel. while user download and see, the downloaded xl/CSV, the data is shown in exponential format. Is there a way to show the same data. without converting into exponential in this case.
To force the string 121212121212121, Excel needs to see ="121212121212121" (a formula whose result is the desired string). =121212121212121 is interpreted as numeric, as is "121212121212121"
Currently, this can be generated by setting the formula of a cell. A sample: https://jsfiddle.net/sheetjs/no2gx45e/
var num = 121212121212121, str = "121212121212121";
var ws = XLSX.utils.aoa_to_sheet([
["num", num ], // { t: "n", n: num }. -> 1.21212E+14 -> number
["str", str ], // { t: "s", v: str } -> 121212121212121 -> number
["numfmla", { f: str } ], // { f: str } -> =121212121212121 -> number
["strfmla", { f: `"${str}"` } ] // { f: '"' + str + '"' } -> ="121212121212121" -> string
]);
We'd accept a PR that looks for strings that may be interpreted as numbers. https://github.com/SheetJS/sheetjs/blob/master/bits/90_utils.js#L111-L112 is where the actual string values are generated, and a simple check using parseInt would address the problem.
While writing string data (example = "121212121212121" -> string of all integer characters) into excel. while user download and see, the downloaded xl/CSV, the data is shown in exponential format. Is there a way to show the same data. without converting into exponential in this case. 22 is the sum so break that down to intergers 2 and 11
Give 2 and 11 value
To force the string 121212121212121, Excel needs to see
="121212121212121"(a formula whose result is the desired string).=121212121212121is interpreted as numeric, as is"121212121212121"Currently, this can be generated by setting the formula of a cell. A sample: https://jsfiddle.net/sheetjs/no2gx45e/
var num = 121212121212121, str = "121212121212121"; var ws = XLSX.utils.aoa_to_sheet([ ["num", num ], // { t: "n", n: num }. -> 1.21212E+14 -> number ["str", str ], // { t: "s", v: str } -> 121212121212121 -> number ["numfmla", { f: str } ], // { f: str } -> =121212121212121 -> number ["strfmla", { f: `"${str}"` } ] // { f: '"' + str + '"' } -> ="121212121212121" -> string ]);We'd accept a PR that looks for strings that may be interpreted as numbers. https://github.com/SheetJS/sheetjs/blob/master/bits/90_utils.js#L111-L112 is where the actual string values are generated, and a simple check using parseInt would address the problem.
Hi, should it do something like this ?
txt = ('' + (o.rawNumbers && val.t == "n" ? val.v : parseInt(format_cell(val,null, o)) === 1 ? val.v : format_cell(val,null, o) ));
Is the issue still open? I would like to take it up if that is the case.
@SheetJSDev Can you please assign this issue to me?
Hi @SheetJSDev , is this issue still unsolved? I would like to take it up