QUestion: correct way to merge sheets #3181

Open
opened 2024-08-21 14:16:10 +00:00 by marmz · 1 comment

As in subject, i don't know the correct way to merge multiple sheets.
Should i iterate the rows, or is there an XLSX.utils method to help adding sheet data at the end of document?

Can i see a code example please?

As in subject, i don't know the correct way to merge multiple sheets. Should i iterate the rows, or is there an XLSX.utils method to help adding sheet data at the end of document? Can i see a code example please?
Owner

No built-in operation yet (we should probably make some sort of generic utility library for this).

If you just want to pull data, you can use an array of arrays intermediate:

  1. use sheet_to_json with the option header: 1 to get an array of arrays from the data in the source worksheet:
var aoa = XLSX.utils.sheet_to_json(ws_src, { header: 1 });

https://docs.sheetjs.com/docs/api/utilities/array#array-of-arrays

  1. use sheet_add_aoa with the option origin: -1 to add to the bottom of the sheet:
XLSX.utils.sheet_add_aoa(ws_dst, aoa, { origin: -1 });

https://docs.sheetjs.com/docs/api/utilities/array#array-of-arrays-input

If you wanted more features, it becomes a bit of a grind since you need to correct formulae and shift merges and other structures.

No built-in operation yet (we should probably make some sort of generic utility library for this). If you just want to pull data, you can use an array of arrays intermediate: 1) use `sheet_to_json` with the option `header: 1` to get an array of arrays from the data in the source worksheet: ```js var aoa = XLSX.utils.sheet_to_json(ws_src, { header: 1 }); ``` https://docs.sheetjs.com/docs/api/utilities/array#array-of-arrays 2) use `sheet_add_aoa` with the option `origin: -1` to add to the bottom of the sheet: ```js XLSX.utils.sheet_add_aoa(ws_dst, aoa, { origin: -1 }); ``` https://docs.sheetjs.com/docs/api/utilities/array#array-of-arrays-input If you wanted more features, it becomes a bit of a grind since you need to correct formulae and shift merges and other structures.
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#3181
No description provided.