sheetjs icon indicating copy to clipboard operation
sheetjs copied to clipboard

Auto converting string data with all integer to exponential.

Open gokinasaiajay opened this issue 3 years ago • 7 comments

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.

gokinasaiajay avatar Mar 13 '22 17:03 gokinasaiajay

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.

SheetJSDev avatar Mar 13 '22 23:03 SheetJSDev

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

Mikecarbon avatar Mar 18 '22 03:03 Mikecarbon

Give 2 and 11 value

Mikecarbon avatar Mar 18 '22 08:03 Mikecarbon

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.

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) ));

Sarfraz-droid avatar Mar 23 '22 07:03 Sarfraz-droid

Is the issue still open? I would like to take it up if that is the case.

anshul137 avatar Oct 05 '22 05:10 anshul137

@SheetJSDev Can you please assign this issue to me?

ZainGulbaz avatar Apr 04 '23 09:04 ZainGulbaz

Hi @SheetJSDev , is this issue still unsolved? I would like to take it up

sayantandasgupta avatar Jul 05 '23 17:07 sayantandasgupta