json_to_sheet
mutates header array #2139
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#2139
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
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 am experiencing the same problem.
In addition, sheets js is mutating the header array passed in, which is not something I would ever expect.
Example:
Originally posted by @paustint in https://github.com/SheetJS/sheetjs/issues/1487#issuecomment-706759470
@paustint Suppose there were two missing fields:
When the sheet is written, both f3 and f4 will be written after f1 and f2. The order is dependent on the order of presentation within the data itself. For example:
The order will start with
f1
thenf2
. The next column will bef4
and then the next column will bef3
. If you flip the order in the array, likethe write order will be
f1
,f2
,f3
,f4
.We needed a way to communicate that ordering back to the caller. Since elements are never removed (they are only appended if data objects have headers that are missing), mutating the array preserves the intent and lets you chain into subsequent calls of
sheet_add_json
:I understand. Many libraries will ignore extra headers if they are not included in the first row of data if a headers array not explicitly specified and I think that sheetsjs has the better approach of not requiring all rows to be the exact same shape.
I now understand the tradeoffs much better, thank you for taking the time to explain.
Now that you understand this, maybe you can help improve the docs :) We'll accept a PR that clarifies the behavior.
@SheetJSDev Hi, This issue is still open. So I raised a PR with suggested Changes
af34ae4178