From 18cd63a548afa1abcddc86a998fdefa3b4cc60c1 Mon Sep 17 00:00:00 2001 From: Kostya Privezentsev Date: Tue, 30 Aug 2022 19:02:48 +0300 Subject: This is a breaking change closes #1332 (#1333) This use `InsertRows` instead of `InsertRow`, and using `InsertCols` instead of `InsertCol` --- adjust.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'adjust.go') diff --git a/adjust.go b/adjust.go index 99d2850..fd570bb 100644 --- a/adjust.go +++ b/adjust.go @@ -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. -- cgit v1.2.1