Number value cells aligned to the left when exporting to an Excel file. #2885
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
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: sheetjs/sheetjs#2885
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?
When we use the XLSX.utils.table_to_sheet() function, the data for number cells are showing as aligned to the left, meaning Exel does not see them as numbers. That is causing issues when we try to create formulas in Excel.
Any number values like 123, 123.99, $123.99 or 12.3% should be exported to Excel and aligned to the right to show they are indeed numerical/currency values and we can create any formulas against them. Thank you.
You can override the default behavior using data attributes, as described in https://docs.sheetjs.com/docs/api/utilities#value-override in the docs.
Someone asked the same question last night in the SheetJS discord.
In the example, the person was generating a cell like
The desired format is discovered by parsing the file with the option
cellNF: true
. In NodeJS the code looks likeThe format was
#,##0.00\ "€";[Red]\-#,##0.00\ "€"
(currency with 2 decimal places, negative in red)The overrides were therefore:
data-t="n"
(numeric cell type)data-v="100"
(cell value -- this is a simple number, no thousands symbols or currency sigil)data-z='#,##0.00\ "€";[Red]\-#,##0.00\ "€"'
(cell number format)Live example: https://jsfiddle.net/e79401pz/
The discussion is interesting and we will try to add some of those details to the docs.