Sending form data to excel only working with set variables. #3104
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#3104
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 right now trying to create a form where all of the data will be sent to an excel. I found this code snippet, and it did work as pasted, but as soon as I got my own data into it it stopped working with the errors:
"Possible unhandled promise rejection id: 2" (got even id 0 and 1 also)
TypeError: js.forEach is not a function (it is undefined)
Here is my code:
You may notice that aside from the copy pasted text I also added "async" behind the function, that is because I would get 2 syntax errors from those 2 await functions and adding async there seemed to do the trick. I am not sure if that makes the problem worse.
I have tried using the data var provided in the snippet and everything works properly. As soon as I remove that and I use the data from the form it doesn't like. It doesn't cross the var ws line. It is seemingly getting stuck at that point.
In terms of my form it does function normally. The console log at the top of the function works (even though it logs the fiels in the wrong order, it's 2 - 3 - 1 - 4 instead of 1 - 2 - 3 - 4)
Thank you in advance for all the help
Are you sure that
data
is an array of objects? After the console line, beforejson_to_sheet
, test ifdata
is an array:It is in
it is indeed not an array of object. I thought they're the same type because typeof() returned the same values.
Anyway I ran
var newArrayDataOfOjbect = Object.entries(data);
and now it seems to work. I just have a small little issue if you can also help me regarding that. Now, with this line, whenever I create a form the first 2 entries I get are 0 and 1. Do you happen to know why that would be?I am also looking to create 1 form in the beginning and keep adding data to it. I am thinking if introducing a boolean before
var wb
that if there is already a form to not execute the command. Would that mean though that the data would be going to the same form? As of right now just doing this just gives me the same errors as beforThank you for your time and help.
Object.entries
returns an array of arrays.Consider a data object like
Then
Object.entries(data)
will look likeEach row object has keys "0" and "1" (corresponding to the two columns), so
json_to_sheet
generates the worksheet you see.If you are happy with the shape but don't want that "0" or "1", you can use
aoa_to_sheet
:If you want a sheet with two rows and one column per field, like
You can pass an array containing only the data object:
If
data
happens to be aFormData
object (you can test withdata instanceof FormData
), you can iterate and construct a plain object:If you want to append data to an existing worksheet, use
sheet_add_json
orsheet_add_aoa