如何使用 Node js 中的 xlsx/sheetjs 包在现有 xlsx 文件中创建新工作表?

Oli*_*ver 2 javascript excel xlsx node.js sheetjs

如何使用 Node js 中的sheetjs 的 xlsx 包在现有的 xlsx 文件中创建/添加新的工作表文件?

到目前为止,这是我针对现有“todo-list.xlsx”文件的代码。

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

我想做这样的事情(这是通过使用 Excel JS 包完成的):

const sheet = workbookStream.addSheet('sheet1');
Run Code Online (Sandbox Code Playgroud)

...但是使用 xlsx 包。

非常感谢您!

Ana*_*oly 6

官方文档中有一个向现有工作簿添加新工作表的示例:

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);
Run Code Online (Sandbox Code Playgroud)

请参阅使用工作簿