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` --- col.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'col.go') diff --git a/col.go b/col.go index 248e22c..f51336d 100644 --- a/col.go +++ b/col.go @@ -657,16 +657,25 @@ func (f *File) GetColWidth(sheet, col string) (float64, error) { return defaultColWidth, err } -// InsertCol provides a function to insert a new column before given column -// index. For example, create a new column before column C in Sheet1: +// InsertCols provides a function to insert new columns before the given column +// name and number of columns. For example, create two columns before column +// C in Sheet1: // -// err := f.InsertCol("Sheet1", "C") -func (f *File) InsertCol(sheet, col string) error { +// err := f.InsertCols("Sheet1", "C", 2) +// +// Use this method with caution, which will affect changes in references such +// as formulas, charts, and so on. If there is any referenced value of the +// worksheet, it will cause a file error when you open it. The excelize only +// partially updates these references currently. +func (f *File) InsertCols(sheet, col string, n int) error { num, err := ColumnNameToNumber(col) if err != nil { return err } - return f.adjustHelper(sheet, columns, num, 1) + if n < 1 || n > MaxColumns { + return ErrColumnNumber + } + return f.adjustHelper(sheet, columns, num, n) } // RemoveCol provides a function to remove single column by given worksheet -- cgit v1.2.1