(I used this page https://github.com/SheetJS/js-xlsx for my chrome extension.)
I have a problem with adding a worksheet to a local workbook.
I want to create a worksheet with data from a page, parse and save the data to a worksheet. This worksheet should be stored in a local workbook, which already has worksheets.
Currently I am creating a new workbook every time and saving only on worksheet. This is a sample working code part for create a worksheet, add it to the workbook and downloading the workbook.
var title = "test";
var url = "xyz";
var data = [
{"A": "Title", "B": title},
{"A": "URL", "B": url},
];
var ws = XLSX.utils.json_to_sheet(data, {skipHeader:true});
var wb = XLSX.utils.book_new();
//Only 31 available characters at the name of the worksheet
while(title.length >= 32){
title = title.substr(0, title.length-1);
}
var ws_name = title;
// Add the worksheet to the workbook
XLSX.utils.book_append_sheet(wb, ws, ws_name);
//create and downloading workbook
XLSX.writeFile(wb, 'test.xlsx');
I would be glad if anyone has any idea how it works to add the created worksheet to an existing local xlsx file.