简体   繁体   中英

How to create a new sheet in an existing xlsx file using xlsx/sheetjs package in node js?

How to create/ add a new sheet file in an already existing xlsx file using the xlsx package by sheetjs in Node js?

This is my code by far, for an existing "todo-list.xlsx" file.

const xlsx = require('xlsx');
workBook = xlsx.readFile("todo-list.xlsx", {cellDates:true});

I would like to do something like this (this is done by using the Excel JS package):

const sheet = workbookStream.addSheet('sheet1');

... but using the xlsx package.

Thank you very much in advanced!

There is an example of adding a new worksheet to an existing workbook In the official documentation:

var ws_name = "SheetJS";
 
/* make worksheet */
var ws_data = [
  [ "S", "h", "e", "e", "t", "J", "S" ],
  [  1 ,  2 ,  3 ,  4 ,  5 ]
];
var ws = XLSX.utils.aoa_to_sheet(ws_data);
 
/* Add the worksheet to the workbook */
XLSX.utils.book_append_sheet(wb, ws, ws_name);

See Working with the Workbook

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM