How to append content in the end of xlsx #876

Closed
opened 2017-11-04 03:27:55 +00:00 by yang24201 · 4 comments
yang24201 commented 2017-11-04 03:27:55 +00:00 (Migrated from github.com)

There are lots of data I want to write to the xlsx file, and I will write in batches. So, the data need to append to the end of file at each time. Do you have any idea to resolve my issue?
Thank you!

There are lots of data I want to write to the xlsx file, and I will write in batches. So, the data need to append to the end of file at each time. Do you have any idea to resolve my issue? Thank you!
jomel commented 2018-01-10 14:17:35 +00:00 (Migrated from github.com)

would XLSX.utils.sheet_add_aoa be any use to you?

would [XLSX.utils.sheet_add_aoa](https://github.com/SheetJS/js-xlsx#utility-functions) be any use to you?
reviewher commented 2018-01-11 06:46:21 +00:00 (Migrated from github.com)

sheet_add_aoa and sheet_add_json helper functions with the origin:-1 option will append rows to the end of the file. For example:

var ws = XLSX.utils.aoa_to_sheet([
  ["Header 1", "Header 2"]
]);
XLSX.utils.sheet_add_aoa(ws, [
  ["Data 1", 1],
  ["Data 2", 2]
], {origin:-1});
XLSX.utils.sheet_add_aoa(ws, [
  ["Data 3", 3],
  ["Data 4", 4],
  ["Data 5", 5]
], {origin:-1});
console.log(XLSX.utils.sheet_to_csv(ws));

will generate the table

Header 1,Header 2
Data 1,1
Data 2,2
Data 3,3
Data 4,4
Data 5,5

To generate an XLSX, just attach to a workbook and follow one of the write recipes:

var wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "WorksheetName");
`sheet_add_aoa` and `sheet_add_json` helper functions with the `origin:-1` option will append rows to the end of the file. For example: ```js var ws = XLSX.utils.aoa_to_sheet([ ["Header 1", "Header 2"] ]); XLSX.utils.sheet_add_aoa(ws, [ ["Data 1", 1], ["Data 2", 2] ], {origin:-1}); XLSX.utils.sheet_add_aoa(ws, [ ["Data 3", 3], ["Data 4", 4], ["Data 5", 5] ], {origin:-1}); console.log(XLSX.utils.sheet_to_csv(ws)); ``` will generate the table ```csv Header 1,Header 2 Data 1,1 Data 2,2 Data 3,3 Data 4,4 Data 5,5 ``` To generate an XLSX, just attach to a workbook and [follow one of the write recipes](https://docs.sheetjs.com/#writing-workbooks): ```js var wb = XLSX.utils.book_new(); XLSX.utils.book_append_sheet(wb, ws, "WorksheetName"); ```
anshulmantri commented 2020-07-20 09:51:39 +00:00 (Migrated from github.com)

Hi i have a question, below code gives me the excel file with 1 html table:
for eg:
var elt = document.getElementById('tbl1');
var wb = XLSX.utils.table_to_book(elt, { sheet: "Sheet JS" });
return dl ?
XLSX.write(wb, { bookType: type, bookSST: true, type: 'base64' }) :
XLSX.writeFile(wb, fn || ('SheetJS.' + (type || 'xlsx')));

What if i have to append multiple html table to the same sheet, how can i achieve it?
eg:
var elt = document.getElementById('tbl1');
var elt2 = document.getElementById('tbl2');

is there a way to append both table objects to one sheet?

Hi i have a question, below code gives me the excel file with 1 html table: for eg: var elt = document.getElementById('tbl1'); var wb = XLSX.utils.table_to_book(elt, { sheet: "Sheet JS" }); return dl ? XLSX.write(wb, { bookType: type, bookSST: true, type: 'base64' }) : XLSX.writeFile(wb, fn || ('SheetJS.' + (type || 'xlsx'))); What if i have to append multiple html table to the same sheet, how can i achieve it? eg: var elt = document.getElementById('tbl1'); var elt2 = document.getElementById('tbl2'); is there a way to append both table objects to one sheet?
ronaldoasilva commented 2020-07-27 13:49:03 +00:00 (Migrated from github.com)

Hi i have a question, below code gives me the excel file with 1 html table:
for eg:
var elt = document.getElementById('tbl1');
var wb = XLSX.utils.table_to_book(elt, { sheet: "Sheet JS" });
return dl ?
XLSX.write(wb, { bookType: type, bookSST: true, type: 'base64' }) :
XLSX.writeFile(wb, fn || ('SheetJS.' + (type || 'xlsx')));

What if i have to append multiple html table to the same sheet, how can i achieve it?
eg:
var elt = document.getElementById('tbl1');
var elt2 = document.getElementById('tbl2');

is there a way to append both table objects to one sheet?

UP!

> Hi i have a question, below code gives me the excel file with 1 html table: > for eg: > var elt = document.getElementById('tbl1'); > var wb = XLSX.utils.table_to_book(elt, { sheet: "Sheet JS" }); > return dl ? > XLSX.write(wb, { bookType: type, bookSST: true, type: 'base64' }) : > XLSX.writeFile(wb, fn || ('SheetJS.' + (type || 'xlsx'))); > > What if i have to append multiple html table to the same sheet, how can i achieve it? > eg: > var elt = document.getElementById('tbl1'); > var elt2 = document.getElementById('tbl2'); > > is there a way to append both table objects to one sheet? UP!
Sign in to join this conversation.
No Milestone
No Assignees
1 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#876
No description provided.