问题
I am trying to read from a excel file, manipulate some data and write to another excel. I am seeing a weird issue when adding rows which have merged cells. They are not getting added as expected in the destination file, the rows are appearing non-merged.
Below is the relevant part of the code. I am using streams and addRow.
const readerOptions = {
sharedStrings: 'cache',
hyperlinks: 'cache',
worksheets: 'emit',
styles: 'cache',
};
const writerOptions = {
filename: fpath,
useStyles: true,
useSharedStrings: true
}
const workbook = new ExcelJS.stream.xlsx.WorkbookWriter(writerOptions)
const myworksheet = workbook.addWorksheet('Sheet 1');
const workbookReader = new ExcelJS.stream.xlsx.WorkbookReader(sheet.path, readerOptions);
workbookReader.read();
workbookReader.on('worksheet', worksheet => {
worksheet.on('row', row => {
const r = myworksheet.addRow();
Object.assign(r, row);
});
});
workbookReader.on('end', async () => {
await workbook.commit();
});
Please find the below images for your reference. first image is actual_result.png and second image is expected_result.png
actual_result
expected_result
来源:https://stackoverflow.com/questions/65320644/addrow-not-adding-merged-cells-correctly-which-are-read-from-source-file