Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto converting string data with all integer to exponential. #2609

Open
gokinasaiajay opened this issue Mar 13, 2022 · 7 comments
Open

Auto converting string data with all integer to exponential. #2609

gokinasaiajay opened this issue Mar 13, 2022 · 7 comments

Comments

@gokinasaiajay
Copy link

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.

@SheetJSDev
Copy link
Contributor

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.

@Mikecarbon
Copy link

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
Copy link

Mikecarbon commented Mar 18, 2022

Give 2 and 11 value

@Sarfraz-droid
Copy link

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

@SheetJS SheetJS deleted a comment from yandice34 Aug 31, 2022
@SheetJS SheetJS deleted a comment from peterkennett Aug 31, 2022
@anshul137
Copy link

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

AbhiramTS added a commit to AbhiramTS/sheetjs that referenced this issue Jan 18, 2023
qburst-harikrishnanp added a commit to qburst/sheetjs that referenced this issue Jan 18, 2023
Check for strings that may be interpreted as numbers (fixes SheetJS#2609)
@ZainGulbaz
Copy link

@SheetJSDev Can you please assign this issue to me?

@sayantandasgupta
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants
@SheetJSDev @gokinasaiajay @sayantandasgupta @anshul137 @Sarfraz-droid @ZainGulbaz @Mikecarbon and others