-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Description
I have complicated accounting document with many rows. I was update package Excelize.
And now, if i calling RemoveRow() in cycle, i receive an error - out of range.
Error location:
RemoveRow() -> adjustHelper() -> adjustMergeCells() -> deleteMergeCell()
Row:
sheet.MergeCells.Cells = append(sheet.MergeCells.Cells[:idx], sheet.MergeCells.Cells[idx+1:]...)
I think you need to replace row:
for i, areaData := range xlsx.MergeCells.Cells {
with:
for i := 0; i < len(xlsx.MergeCells.Cells); i++ {
in method adjustMergeCells(). And decrement index after each calling method deleteMergeCell().
Like this:
func (f *File) adjustMergeCells(xlsx *xlsxWorksheet, dir adjustDirection, num, offset int) error {
if xlsx.MergeCells == nil {
return nil
}
// for i, areaData := range xlsx.MergeCells.Cells { // ---
for i := 0; i < len(xlsx.MergeCells.Cells); i++ { // +++
areaData := xlsx.MergeCells.Cells[i] // +++
coordinates, err := f.areaRefToCoordinates(areaData.Ref)
if err != nil {
return err
}
x1, y1, x2, y2 := coordinates[0], coordinates[1], coordinates[2], coordinates[3]
if dir == rows {
if y1 == num && y2 == num && offset < 0 {
f.deleteMergeCell(xlsx, i)
i-- // +++
}
y1 = f.adjustMergeCellsHelper(y1, num, offset)
y2 = f.adjustMergeCellsHelper(y2, num, offset)
} else {
if x1 == num && x2 == num && offset < 0 {
f.deleteMergeCell(xlsx, i)
i-- // +++
}
x1 = f.adjustMergeCellsHelper(x1, num, offset)
x2 = f.adjustMergeCellsHelper(x2, num, offset)
}
if x1 == x2 && y1 == y2 {
f.deleteMergeCell(xlsx, i)
i-- // +++
}
if areaData.Ref, err = f.coordinatesToAreaRef([]int{x1, y1, x2, y2}); err != nil {
return err
}
}
return nil
}
This was solve problem for me. But i did not go deep into solving this problem.
Excelize version or commit ID:
last update
Environment details (OS, Microsoft Excel™ version, physical, etc.):
Ubuntu 16.04
Activity
xuri commentedon Jul 16, 2019
Hi @artsb, thanks for your feedback. Please provide code and testing file attachment if you can.
artsb commentedon Jul 18, 2019
upd.xlsx
Template code:
dealElems - slice with data.
xuri commentedon Jul 20, 2019
Hi @artsb, thanks for your issue. I have fixed it. Please try to upgrade the library with the master branch code.
artsb commentedon Jul 21, 2019
I'm glad to help you ;) Thanks for your work!
Fix qax-os#437, recalculate offset for merged cells adjuster
Fix qax-os#437, recalculate offset for merged cells adjuster