summaryrefslogtreecommitdiff
path: root/table.go
diff options
context:
space:
mode:
Diffstat (limited to 'table.go')
-rw-r--r--table.go49
1 files changed, 28 insertions, 21 deletions
diff --git a/table.go b/table.go
index 413118c..84445b7 100644
--- a/table.go
+++ b/table.go
@@ -129,28 +129,18 @@ func (f *File) addSheetTable(sheet string, rID int) error {
return err
}
-// addTable provides a function to add table by given worksheet name,
-// coordinate area and format set.
-func (f *File) addTable(sheet, tableXML string, x1, y1, x2, y2, i int, formatSet *formatTable) error {
- // Correct the minimum number of rows, the table at least two lines.
- if y1 == y2 {
- y2++
- }
-
- // Correct table reference coordinate area, such correct C1:B3 to B1:C3.
- ref, err := f.coordinatesToAreaRef([]int{x1, y1, x2, y2})
- if err != nil {
- return err
- }
-
- var tableColumn []*xlsxTableColumn
-
- idx := 0
+// setTableHeader provides a function to set cells value in header row for the
+// table.
+func (f *File) setTableHeader(sheet string, x1, y1, x2 int) ([]*xlsxTableColumn, error) {
+ var (
+ tableColumns []*xlsxTableColumn
+ idx int
+ )
for i := x1; i <= x2; i++ {
idx++
cell, err := CoordinatesToCellName(i, y1)
if err != nil {
- return err
+ return tableColumns, err
}
name, _ := f.GetCellValue(sheet, cell)
if _, err := strconv.Atoi(name); err == nil {
@@ -160,11 +150,28 @@ func (f *File) addTable(sheet, tableXML string, x1, y1, x2, y2, i int, formatSet
name = "Column" + strconv.Itoa(idx)
_ = f.SetCellStr(sheet, cell, name)
}
- tableColumn = append(tableColumn, &xlsxTableColumn{
+ tableColumns = append(tableColumns, &xlsxTableColumn{
ID: idx,
Name: name,
})
}
+ return tableColumns, nil
+}
+
+// addTable provides a function to add table by given worksheet name,
+// coordinate area and format set.
+func (f *File) addTable(sheet, tableXML string, x1, y1, x2, y2, i int, formatSet *formatTable) error {
+ // Correct the minimum number of rows, the table at least two lines.
+ if y1 == y2 {
+ y2++
+ }
+
+ // Correct table reference coordinate area, such correct C1:B3 to B1:C3.
+ ref, err := f.coordinatesToAreaRef([]int{x1, y1, x2, y2})
+ if err != nil {
+ return err
+ }
+ tableColumns, _ := f.setTableHeader(sheet, x1, y1, x2)
name := formatSet.TableName
if name == "" {
name = "Table" + strconv.Itoa(i)
@@ -179,8 +186,8 @@ func (f *File) addTable(sheet, tableXML string, x1, y1, x2, y2, i int, formatSet
Ref: ref,
},
TableColumns: &xlsxTableColumns{
- Count: idx,
- TableColumn: tableColumn,
+ Count: len(tableColumns),
+ TableColumn: tableColumns,
},
TableStyleInfo: &xlsxTableStyleInfo{
Name: formatSet.TableStyle,