Write worksheet to xml file with ExcelJS without writing the whole workbook

40 Views Asked by At

I would like to know if there is any way using ExcelJS to write a specific worksheet directly to an xml file, without writing the whole workbook, like in the following pseudo code:

const ExcelJS = require('exceljs');

const workbook = new ExcelJS.Workbook();

workbook.xlsx.readFile(ExcelTemplate);

let worksheet = workbook.getWorksheet(worksheetName);

worksheet.getCell(1, 1).value = 123;

// Instead ow writing the full workbook, write the worksheet as xml
// workbook.xlsx.writeFile(`${outputDir}/${fileName}.xlsx`);
worksheet.xlsx.writeFile(`${outputDir}/${fileName}.xml`);

I'm asking this because loading my ExcelTemplate into ExcelJS breaks some feature (charts, named range...), so I end up to a workaround where I use ExcelJS to fullfill with data an excel file, then I need to replace the blank data worksheet of the ExcelTemplate with the fulfilled one. Writing the workseeth to xml, will simplify the process

Many thanks to everyone!

0

There are 0 best solutions below