Fixed PR #356 regression RemoveCol() broken (#365)

This commit is contained in:
Veniamin Albaev 2019-03-21 13:44:30 +03:00 committed by xuri
parent 70b1a29165
commit 7d197c6d89
2 changed files with 9 additions and 7 deletions

9
col.go
View File

@ -337,11 +337,12 @@ func (f *File) RemoveCol(sheet, col string) {
xlsx := f.workSheetReader(sheet) xlsx := f.workSheetReader(sheet)
for rowIdx := range xlsx.SheetData.Row { for rowIdx := range xlsx.SheetData.Row {
rowData := xlsx.SheetData.Row[rowIdx] rowData := &xlsx.SheetData.Row[rowIdx]
for colIdx, cellData := range rowData.C { for colIdx := range rowData.C {
colName, _, _ := SplitCellName(cellData.R) colName, _, _ := SplitCellName(rowData.C[colIdx].R)
if colName == col { 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
} }
} }
} }

View File

@ -379,9 +379,10 @@ func (f *File) RemoveRow(sheet string, row int) {
if row > len(xlsx.SheetData.Row) { if row > len(xlsx.SheetData.Row) {
return return
} }
for i, r := range xlsx.SheetData.Row { for rowIdx := range xlsx.SheetData.Row {
if r.R == row { if xlsx.SheetData.Row[rowIdx].R == row {
xlsx.SheetData.Row = append(xlsx.SheetData.Row[:i], xlsx.SheetData.Row[i+1:]...) xlsx.SheetData.Row = append(xlsx.SheetData.Row[:rowIdx],
xlsx.SheetData.Row[rowIdx+1:]...)[:len(xlsx.SheetData.Row)-1]
f.adjustHelper(sheet, rows, row, -1) f.adjustHelper(sheet, rows, row, -1)
return return
} }