sheetjs icon indicating copy to clipboard operation
sheetjs copied to clipboard

How to append content in the end of xlsx

Open yang24201 opened this issue 9 years ago • 4 comments

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!

yang24201 avatar Nov 04 '17 03:11 yang24201

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

jomel avatar Jan 10 '18 14:01 jomel

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");

reviewher avatar Jan 11 '18 06:01 reviewher

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?

anshulmantri avatar Jul 20 '20 09:07 anshulmantri

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!

ronaldoasilva avatar Jul 27 '20 13:07 ronaldoasilva