diff options
author | Kostya Privezentsev <privezentsev@gmail.com> | 2022-08-30 19:02:48 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-31 00:02:48 +0800 |
commit | 18cd63a548afa1abcddc86a998fdefa3b4cc60c1 (patch) | |
tree | 20abe577307ce6d072900f0b98fee57e06133eea /adjust.go | |
parent | bef49e40eec508a6413e80ee5df7df52f7827424 (diff) |
This is a breaking change closes #1332 (#1333)
This use `InsertRows` instead of `InsertRow`, and using `InsertCols` instead of `InsertCol`
Diffstat (limited to 'adjust.go')
-rw-r--r-- | adjust.go | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -42,9 +42,12 @@ func (f *File) adjustHelper(sheet string, dir adjustDirection, num, offset int) } sheetID := f.getSheetID(sheet) if dir == rows { - f.adjustRowDimensions(ws, num, offset) + err = f.adjustRowDimensions(ws, num, offset) } else { - f.adjustColDimensions(ws, num, offset) + err = f.adjustColDimensions(ws, num, offset) + } + if err != nil { + return err } f.adjustHyperlinks(ws, sheet, dir, num, offset) f.adjustTable(ws, sheet, dir, num, offset) @@ -69,28 +72,36 @@ func (f *File) adjustHelper(sheet string, dir adjustDirection, num, offset int) // adjustColDimensions provides a function to update column dimensions when // inserting or deleting rows or columns. -func (f *File) adjustColDimensions(ws *xlsxWorksheet, col, offset int) { +func (f *File) adjustColDimensions(ws *xlsxWorksheet, col, offset int) error { for rowIdx := range ws.SheetData.Row { for colIdx, v := range ws.SheetData.Row[rowIdx].C { cellCol, cellRow, _ := CellNameToCoordinates(v.R) if col <= cellCol { if newCol := cellCol + offset; newCol > 0 { + if newCol > MaxColumns { + return ErrColumnNumber + } ws.SheetData.Row[rowIdx].C[colIdx].R, _ = CoordinatesToCellName(newCol, cellRow) } } } } + return nil } // adjustRowDimensions provides a function to update row dimensions when // inserting or deleting rows or columns. -func (f *File) adjustRowDimensions(ws *xlsxWorksheet, row, offset int) { +func (f *File) adjustRowDimensions(ws *xlsxWorksheet, row, offset int) error { for i := range ws.SheetData.Row { r := &ws.SheetData.Row[i] if newRow := r.R + offset; r.R >= row && newRow > 0 { + if newRow >= TotalRows { + return ErrMaxRows + } f.adjustSingleRowDimensions(r, newRow) } } + return nil } // adjustSingleRowDimensions provides a function to adjust single row dimensions. |