XLSX.utils.table_to_book convert #673
Labels
No Label
DBF
Dates
Defined Names
Features
Formula
HTML
Images
Infrastructure
Integration
International
ODS
Operations
Performance
PivotTables
Pro
Protection
Read Bug
SSF
SYLK
Style
Write Bug
good first issue
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sheetjs/sheetjs#673
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I use XLSX.utils.table_to_book to download the excel file from a table in the html page.
There's something wrong in the auto converting.
Some values like 11% will be converted to date.
How can I get it to convert correctly?
Here is the example:
https://jsfiddle.net/f8rxfrj5/2/
@huhm good catch! the JS native date mechanism recognizes that as a date.
We can check for common numeric formats before falling back to the date.
+1 Having the same issue
Any ETA to fix this bug please? If it requires time, is there a way to disable automatic date formatting entirely as I don't need it as a temporary solution?
I finally use the method: wb.addSheetFromArray in which way I can format by myself;
Is the problem here? https://github.com/SheetJS/js-xlsx/blob/master/xlsx.js#L1511
I think raw numbers in the CSV should not be dates.
The funny thing is, that when parsing CSV, in
"1"
is interpreted as date, but in(without quotes) it isn't
@huhm @nknapp tl;dr: it's a complex problem, you can sidestep the whole thing by passing
raw:true
option toXLSX.read
andXLSX.readFile
CSV, like the Lotus formatted PRN and other simple plaintext formats, leaves value interpretation up to the application. Even the "spec" RFC4180 is ambiguous :(
So what does Excel do? It appears that they interpret values as if you typed them into the formula bar. Formulas are processed -- try the following CSV data in Excel:
In the percentage case case, the problem is that the number matching is too strict (https://github.com/SheetJS/js-xlsx/blob/master/bits/40_harb.js#L534 in the bits, https://github.com/SheetJS/js-xlsx/blob/master/xlsx.js#L5678 in the final script).
In general, the problem is compounded by localization (try changing your computer regional settings!)
Short term solution: as part of https://github.com/SheetJS/js-xlsx/issues/719 we added a
raw
option toXLSX.read
andXLSX.readFile
-- this skips all of the guess work and just returns strings. See https://runkit.com/sheetjs/5964eadbea82990011acd7f7 for a demonstration.Long term solution: eventually the libraries will need to process and understand locale information.
With
xlsx.read(data, { raw: true})
the column with the value"1"
still appears asMy short term solution now is to create a fork that disables date-parsing altogether (we don't need it).
But once this is fixed, I would like to go back to the original library again.
@nknapp Are you testing against xlsx 0.10.8? What does
console.log(xlsx.version)
show?Against 0.10.8 it appears to give the correct value for your first example:
If you just tested against
"1"
it's because the parser isn't recognizing it as CSV:The same fix has to be applied to the PRN parser. Can you check if the following diff resolves the issue:
You can either apply it directly to xlsx.js or apply to bits/40_harb.js and run make.
(Note: for plaintext files, if there is no comma or tab character, the parser assumes the output is Lotus Formatted Text PRN)
I had version "0.10.5", sorry about that. "raw:true" works for my CSV (which I sadly can't share) with "0.10.8".
But it keeps the surrounding quotes in the value and removing those may probably only be done in CSV and not when reading xlsx-files.
I think it is easier and safer for me to stick to my fork at the moment, but I would like to thank you for your quick responses.
it worked for me. I love you ♥