Validate heder #2821

Closed
opened 2022-11-08 13:53:56 +00:00 by StefanGhiban · 1 comment

Hi! I would like to know if there is a way to give an error to the user if the excel they want to import does not have the specified columns. For example, when I am doing a sheet_to_json, I want to make sure only some columns are being extracted, and if they do no exist in the excel, the user should get an error.

Hi! I would like to know if there is a way to give an error to the user if the excel they want to import does not have the specified columns. For example, when I am doing a sheet_to_json, I want to make sure only some columns are being extracted, and if they do no exist in the excel, the user should get an error.
Owner

You can scan the first row to get the header labels:

/* create range covering the first row */
var range = XLSX.utils.decode_range(ws["!ref"]);
range.e.r = range.s.r;

/* get data as an array of arrays */
var aoa = XLSX.utils.sheet_to_json(ws, {header:1, range});
var headers = aoa[0];

headers will be an array of the headers used as keys in sheet_to_json.

You can scan the first row to get the header labels: ```js /* create range covering the first row */ var range = XLSX.utils.decode_range(ws["!ref"]); range.e.r = range.s.r; /* get data as an array of arrays */ var aoa = XLSX.utils.sheet_to_json(ws, {header:1, range}); var headers = aoa[0]; ``` `headers` will be an array of the headers used as keys in `sheet_to_json`.
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#2821
No description provided.