renaming of header fields #2944

Closed
opened 2023-05-16 06:46:41 +00:00 by 1batu · 2 comments
let newHeaders = ['name', 'phone', 'email','childs'];
let worksheet = workbook.Sheets[workbook.SheetNames[0]];
worksheet['A1'] = { t: 's', v: newHeaders[0] };
worksheet['B1'] = { t: 's', v: newHeaders[1] };
worksheet['C1'] = { t: 's', v: newHeaders[2] };
worksheet['D1'] = { t: 's', v: newHeaders[3] };

If you set the header to zero from the settings, you will reach the solution.

let rowObject = XLSX.utils.sheet_to_json(workbook.Sheets[sheet], {
header: 0,
raw: false,
blankrows: false,
});
``` let newHeaders = ['name', 'phone', 'email','childs']; let worksheet = workbook.Sheets[workbook.SheetNames[0]]; worksheet['A1'] = { t: 's', v: newHeaders[0] }; worksheet['B1'] = { t: 's', v: newHeaders[1] }; worksheet['C1'] = { t: 's', v: newHeaders[2] }; worksheet['D1'] = { t: 's', v: newHeaders[3] }; ``` If you set the header to zero from the settings, you will reach the solution. ``` let rowObject = XLSX.utils.sheet_to_json(workbook.Sheets[sheet], { header: 0, raw: false, blankrows: false, }); ```
Owner

What is the question?

FYI: https://docs.sheetjs.com/docs/getting-started/example#clean-up-workbook shows a more natural approach for renaming headers if you want to mutate the worksheet:

XLSX.utils.sheet_add_aoa(workbook.Sheets[workbook.SheetNames[0]], newHeaders, { origin: "A1" });
What is the question? FYI: https://docs.sheetjs.com/docs/getting-started/example#clean-up-workbook shows a more natural approach for renaming headers if you want to mutate the worksheet: ```js XLSX.utils.sheet_add_aoa(workbook.Sheets[workbook.SheetNames[0]], newHeaders, { origin: "A1" }); ```
Owner

If you can clarify the question further, we can reopen the issue.

If you can clarify the question further, we can reopen the issue.
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#2944
No description provided.