From 7d197c6d8963c4d7b6ba12b1f37c4bf1c9d0dade Mon Sep 17 00:00:00 2001 From: Veniamin Albaev Date: Thu, 21 Mar 2019 13:44:30 +0300 Subject: [PATCH] Fixed PR #356 regression RemoveCol() broken (#365) --- col.go | 9 +++++---- rows.go | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/col.go b/col.go index 2362c84..7eb7831 100644 --- a/col.go +++ b/col.go @@ -337,11 +337,12 @@ func (f *File) RemoveCol(sheet, col string) { xlsx := f.workSheetReader(sheet) for rowIdx := range xlsx.SheetData.Row { - rowData := xlsx.SheetData.Row[rowIdx] - for colIdx, cellData := range rowData.C { - colName, _, _ := SplitCellName(cellData.R) + rowData := &xlsx.SheetData.Row[rowIdx] + for colIdx := range rowData.C { + colName, _, _ := SplitCellName(rowData.C[colIdx].R) if colName == col { - rowData.C = append(rowData.C[:colIdx], rowData.C[colIdx+1:]...) + rowData.C = append(rowData.C[:colIdx], rowData.C[colIdx+1:]...)[:len(rowData.C)-1] + break } } } diff --git a/rows.go b/rows.go index c2b4939..54c2046 100644 --- a/rows.go +++ b/rows.go @@ -379,9 +379,10 @@ func (f *File) RemoveRow(sheet string, row int) { if row > len(xlsx.SheetData.Row) { return } - for i, r := range xlsx.SheetData.Row { - if r.R == row { - xlsx.SheetData.Row = append(xlsx.SheetData.Row[:i], xlsx.SheetData.Row[i+1:]...) + for rowIdx := range xlsx.SheetData.Row { + if xlsx.SheetData.Row[rowIdx].R == row { + xlsx.SheetData.Row = append(xlsx.SheetData.Row[:rowIdx], + xlsx.SheetData.Row[rowIdx+1:]...)[:len(xlsx.SheetData.Row)-1] f.adjustHelper(sheet, rows, row, -1) return }