summaryrefslogtreecommitdiff
path: root/adjust.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2022-11-11 01:50:07 +0800
committerxuri <xuri.me@gmail.com>2022-11-11 01:50:07 +0800
commit58b5dae5eb4948a3cde238ced1ae05db159749f5 (patch)
treeea265793558433a3f0a143bb7aa7f408eafd7408 /adjust.go
parent8753950d62c150034a919599a7762cef19035552 (diff)
Support update column style when inserting or deleting columns
- Go Modules dependencies upgrade - Unify internal variable name - Unit test updated
Diffstat (limited to 'adjust.go')
-rw-r--r--adjust.go46
1 files changed, 45 insertions, 1 deletions
diff --git a/adjust.go b/adjust.go
index 65e82fc..bf89927 100644
--- a/adjust.go
+++ b/adjust.go
@@ -70,6 +70,50 @@ func (f *File) adjustHelper(sheet string, dir adjustDirection, num, offset int)
return nil
}
+// adjustCols provides a function to update column style when inserting or
+// deleting columns.
+func (f *File) adjustCols(ws *xlsxWorksheet, col, offset int) error {
+ if ws.Cols == nil {
+ return nil
+ }
+ for i := 0; i < len(ws.Cols.Col); i++ {
+ if offset > 0 {
+ if ws.Cols.Col[i].Max+1 == col {
+ ws.Cols.Col[i].Max += offset
+ continue
+ }
+ if ws.Cols.Col[i].Min >= col {
+ ws.Cols.Col[i].Min += offset
+ ws.Cols.Col[i].Max += offset
+ continue
+ }
+ if ws.Cols.Col[i].Min < col && ws.Cols.Col[i].Max >= col {
+ ws.Cols.Col[i].Max += offset
+ }
+ }
+ if offset < 0 {
+ if ws.Cols.Col[i].Min == col && ws.Cols.Col[i].Max == col {
+ if len(ws.Cols.Col) > 1 {
+ ws.Cols.Col = append(ws.Cols.Col[:i], ws.Cols.Col[i+1:]...)
+ } else {
+ ws.Cols.Col = nil
+ }
+ i--
+ continue
+ }
+ if ws.Cols.Col[i].Min > col {
+ ws.Cols.Col[i].Min += offset
+ ws.Cols.Col[i].Max += offset
+ continue
+ }
+ if ws.Cols.Col[i].Min <= col && ws.Cols.Col[i].Max >= col {
+ ws.Cols.Col[i].Max += offset
+ }
+ }
+ }
+ return nil
+}
+
// adjustColDimensions provides a function to update column dimensions when
// inserting or deleting rows or columns.
func (f *File) adjustColDimensions(ws *xlsxWorksheet, col, offset int) error {
@@ -91,7 +135,7 @@ func (f *File) adjustColDimensions(ws *xlsxWorksheet, col, offset int) error {
}
}
}
- return nil
+ return f.adjustCols(ws, col, offset)
}
// adjustRowDimensions provides a function to update row dimensions when