addRow() not adding merged cells correctly which are read from source file

笑着哭i 提交于 2020-12-27 05:54:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!