Sheetjs: How to append content in the end of xlsx

Created on 4 Nov 2017  路  4Comments  路  Source: SheetJS/sheetjs

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!

Operations

Most helpful comment

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

All 4 comments

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

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

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?

UP!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jamespan0 picture jamespan0  路  3Comments

Alex0007 picture Alex0007  路  3Comments

gustavosimil picture gustavosimil  路  3Comments

DannyRyman picture DannyRyman  路  3Comments

sudhakar-sekar picture sudhakar-sekar  路  3Comments