Contents of sheet not being exported properly #2972
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#2972
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'm requesting a json response from an api and when I try and turn that response into a excel sheet I am only able to export the headers of my response and not the content
Here is my block of code:
When looking at the ws object I can see it is populated with all the headers and content I want mapped to the right cells but when I actually export all I have is an excel sheet full of headers
Can you log the
response
and confirm it is an actual JS array of objects? If it is a string like'[{"a":1,"b":2},{"a":3,"b":4}]
you will need something like:If that doesn't work, please share the contents of
response
.I believe it should be since it is being processed correctly by json_to_sheet
I attached images below that show the value of both response and ws after the json_to_sheet function
When the property is an object that is not a date, it is assumed to be a cell object and will be passed thru. We can eventually add some validation.
To fix your export, since it looks like those fields are arrays, you can pull the first value of each array property:
If you're generally curious, https://docs.sheetjs.com/docs/getting-started/example#raw-data discusses how you can look at your dataset and flatten to an array of simple objects.
Ahh okay. I see. That's good to know.
The code you provided did the trick, I'll read though the docs on flattening datasets.
Thanks for your help!