You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function to delete the specified rows, the merged cells of all subsequent rows will be unmerged.
Lib version: 4.4.0
Steps To Reproduce
For example, there is a worksheet with 2 rows, where A2-O2 of the second row is merged. Now I use worksheet.spliceRows(1,1) to delete the first row. At this time, the original second row moves up to the first row, but the merged state of A1-O1 will be cancelled.
Download the test file in the attachment to the local machine, run the following test code, and then observe the difference between the newly generated xlsx file and the original file, and you can find the problem.
Normally, after the first row is deleted, the merged state of subsequent rows should not change.
Possible solution (optional, but very helpful):
The problem lies in the Worksheet.spliceRows function. The handling of cell merging should be added at line 508 of the Worksheet.js file, similar to the merging handling at line 528. The newly added code is as follows.
spliceRows(start,count, ...inserts){// same problem as row.splice, except worse.constnKeep=start+count;constnInserts=inserts.length;constnExpand=nInserts-count;constnEnd=this._rows.length;leti;letrSrc;if(nExpand<0){// remove rowsif(start===nEnd){this._rows[nEnd-1]=undefined;}for(i=nKeep;i<=nEnd;i++){rSrc=this._rows[i-1];if(rSrc){constrDst=this.getRow(i+nExpand);rDst.values=rSrc.values;rDst.style=rSrc.style;rDst.height=rSrc.height;// eslint-disable-next-line no-loop-funcrSrc.eachCell({includeEmpty: true},(cell,colNumber)=>{rDst.getCell(colNumber).style=cell.style;// remerge cells accounting for insert offset// this is what i addedif(cell._value.constructor.name==='MergeValue'){constcellToBeMerged=this.getRow(cell._row._number+nExpand).getCell(colNumber);constprevMaster=cell._value._master;constnewMaster=this.getRow(prevMaster._row._number+nExpand).getCell(prevMaster._column._number);cellToBeMerged.merge(newMaster);}});this._rows[i-1]=undefined;}else{this._rows[i+nExpand-1]=undefined;}}}elseif(nExpand>0){// insert new cellsfor(i=nEnd;i>=nKeep;i--){rSrc=this._rows[i-1];if(rSrc){constrDst=this.getRow(i+nExpand);rDst.values=rSrc.values;rDst.style=rSrc.style;rDst.height=rSrc.height;// eslint-disable-next-line no-loop-funcrSrc.eachCell({includeEmpty: true},(cell,colNumber)=>{rDst.getCell(colNumber).style=cell.style;// remerge cells accounting for insert offsetif(cell._value.constructor.name==='MergeValue'){constcellToBeMerged=this.getRow(cell._row._number+nInserts).getCell(colNumber);constprevMaster=cell._value._master;constnewMaster=this.getRow(prevMaster._row._number+nInserts).getCell(prevMaster._column._number);cellToBeMerged.merge(newMaster);}});}else{this._rows[i+nExpand-1]=undefined;}}}// now copy over the new valuesfor(i=0;i<nInserts;i++){constrDst=this.getRow(start+i);rDst.style={};rDst.values=inserts[i];}// account for defined namesthis.workbook.definedNames.spliceRows(this.name,start,count,nInserts);}
The text was updated successfully, but these errors were encountered:
🐛 Bug Report
After using the
function to delete the specified rows, the merged cells of all subsequent rows will be unmerged.
Lib version: 4.4.0
Steps To Reproduce
For example, there is a worksheet with 2 rows, where A2-O2 of the second row is merged. Now I use worksheet.spliceRows(1,1) to delete the first row. At this time, the original second row moves up to the first row, but the merged state of A1-O1 will be cancelled.
Download the test file in the attachment to the local machine, run the following test code, and then observe the difference between the newly generated xlsx file and the original file, and you can find the problem.
spiceRows-example.xlsx
The expected behaviour:
Normally, after the first row is deleted, the merged state of subsequent rows should not change.
Possible solution (optional, but very helpful):
The problem lies in the Worksheet.spliceRows function. The handling of cell merging should be added at line 508 of the Worksheet.js file, similar to the merging handling at line 528. The newly added code is as follows.
The text was updated successfully, but these errors were encountered: