how to delete a worksheet from a workbook in Node.js? // TypeError: Cannot read property 'delete' of undefined

how to delete a worksheet from a workbook in Node.js? // TypeError: Cannot read property 'delete' of undefined

我需要从 Node.js 的 Excel 的工作簿中删除一个工作表。我使用 SheetJs(我更希望需要一个使用这个的答案,但我非常感谢所有其他可能性,我可以改变)。找了好几天都没找到解决办法

所以我有这个(如果你需要测试代码):

const xlsx = require('xlsx');
workBook = xlsx.readFile("todo-list.xlsx", {cellDates:true});
const headerData = ["Id", "Name", "Description", "Due Date", "Priority", "Status", "Notes"];
const workSheet = xlsx.utils.aoa_to_sheet([headerData]);
xlsx.utils.book_append_sheet(workBook, workSheet,"TO-DEL");

我试过了,但没用:

workSheet.delete();

或者这个...

workBook.Sheets["TO-DEL"].delete();

结局是这样的:

xlsx.writeFile(workBook, 'todo-list.xlsx');

错误是: TypeError: 无法读取未定义的 属性 'delete'

您对此有任何想法或经验可以帮助我吗?非常感谢任何帮助!

这很完美:

const Excel = require('exceljs');

const workbook = new Excel.Workbook();
workbook.xlsx.readFile("todo-list.xlsx").then(function() {
        const worksheet = workbook.getWorksheet("Sheet1");
        console.log(worksheet);
        workbook.removeWorksheet(worksheet.id);
        return workbook.xlsx.writeFile( "todo-list.xlsx");
});