summaryrefslogtreecommitdiff
path: root/table.go
diff options
context:
space:
mode:
Diffstat (limited to 'table.go')
-rw-r--r--table.go60
1 files changed, 30 insertions, 30 deletions
diff --git a/table.go b/table.go
index 7ef7562..f7cac20 100644
--- a/table.go
+++ b/table.go
@@ -20,12 +20,12 @@ import (
"strings"
)
-// parseFormatTableSet provides a function to parse the format settings of the
+// parseTableOptions provides a function to parse the format settings of the
// table with default value.
-func parseFormatTableSet(formatSet string) (*formatTable, error) {
- format := formatTable{ShowRowStripes: true}
- err := json.Unmarshal(parseFormatSet(formatSet), &format)
- return &format, err
+func parseTableOptions(opts string) (*tableOptions, error) {
+ options := tableOptions{ShowRowStripes: true}
+ err := json.Unmarshal(fallbackOptions(opts), &options)
+ return &options, err
}
// AddTable provides the method to add table in a worksheet by given worksheet
@@ -57,8 +57,8 @@ func parseFormatTableSet(formatSet string) (*formatTable, error) {
// TableStyleLight1 - TableStyleLight21
// TableStyleMedium1 - TableStyleMedium28
// TableStyleDark1 - TableStyleDark11
-func (f *File) AddTable(sheet, hCell, vCell, format string) error {
- formatSet, err := parseFormatTableSet(format)
+func (f *File) AddTable(sheet, hCell, vCell, opts string) error {
+ options, err := parseTableOptions(opts)
if err != nil {
return err
}
@@ -91,7 +91,7 @@ func (f *File) AddTable(sheet, hCell, vCell, format string) error {
return err
}
f.addSheetNameSpace(sheet, SourceRelationship)
- if err = f.addTable(sheet, tableXML, hCol, hRow, vCol, vRow, tableID, formatSet); err != nil {
+ if err = f.addTable(sheet, tableXML, hCol, hRow, vCol, vRow, tableID, options); err != nil {
return err
}
f.addContentTypePart(tableID, "table")
@@ -160,7 +160,7 @@ func (f *File) setTableHeader(sheet string, x1, y1, x2 int) ([]*xlsxTableColumn,
// addTable provides a function to add table by given worksheet name,
// range reference and format set.
-func (f *File) addTable(sheet, tableXML string, x1, y1, x2, y2, i int, formatSet *formatTable) error {
+func (f *File) addTable(sheet, tableXML string, x1, y1, x2, y2, i int, opts *tableOptions) error {
// Correct the minimum number of rows, the table at least two lines.
if y1 == y2 {
y2++
@@ -172,7 +172,7 @@ func (f *File) addTable(sheet, tableXML string, x1, y1, x2, y2, i int, formatSet
return err
}
tableColumns, _ := f.setTableHeader(sheet, x1, y1, x2)
- name := formatSet.TableName
+ name := opts.TableName
if name == "" {
name = "Table" + strconv.Itoa(i)
}
@@ -190,11 +190,11 @@ func (f *File) addTable(sheet, tableXML string, x1, y1, x2, y2, i int, formatSet
TableColumn: tableColumns,
},
TableStyleInfo: &xlsxTableStyleInfo{
- Name: formatSet.TableStyle,
- ShowFirstColumn: formatSet.ShowFirstColumn,
- ShowLastColumn: formatSet.ShowLastColumn,
- ShowRowStripes: formatSet.ShowRowStripes,
- ShowColumnStripes: formatSet.ShowColumnStripes,
+ Name: opts.TableStyle,
+ ShowFirstColumn: opts.ShowFirstColumn,
+ ShowLastColumn: opts.ShowLastColumn,
+ ShowRowStripes: opts.ShowRowStripes,
+ ShowColumnStripes: opts.ShowColumnStripes,
},
}
table, _ := xml.Marshal(t)
@@ -202,12 +202,12 @@ func (f *File) addTable(sheet, tableXML string, x1, y1, x2, y2, i int, formatSet
return nil
}
-// parseAutoFilterSet provides a function to parse the settings of the auto
+// parseAutoFilterOptions provides a function to parse the settings of the auto
// filter.
-func parseAutoFilterSet(formatSet string) (*formatAutoFilter, error) {
- format := formatAutoFilter{}
- err := json.Unmarshal([]byte(formatSet), &format)
- return &format, err
+func parseAutoFilterOptions(opts string) (*autoFilterOptions, error) {
+ options := autoFilterOptions{}
+ err := json.Unmarshal([]byte(opts), &options)
+ return &options, err
}
// AutoFilter provides the method to add auto filter in a worksheet by given
@@ -279,7 +279,7 @@ func parseAutoFilterSet(formatSet string) (*formatAutoFilter, error) {
// x < 2000
// col < 2000
// Price < 2000
-func (f *File) AutoFilter(sheet, hCell, vCell, format string) error {
+func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error {
hCol, hRow, err := CellNameToCoordinates(hCell)
if err != nil {
return err
@@ -297,7 +297,7 @@ func (f *File) AutoFilter(sheet, hCell, vCell, format string) error {
vRow, hRow = hRow, vRow
}
- formatSet, _ := parseAutoFilterSet(format)
+ options, _ := parseAutoFilterOptions(opts)
cellStart, _ := CoordinatesToCellName(hCol, hRow, true)
cellEnd, _ := CoordinatesToCellName(vCol, vRow, true)
ref, filterDB := cellStart+":"+cellEnd, "_xlnm._FilterDatabase"
@@ -328,12 +328,12 @@ func (f *File) AutoFilter(sheet, hCell, vCell, format string) error {
}
}
refRange := vCol - hCol
- return f.autoFilter(sheet, ref, refRange, hCol, formatSet)
+ return f.autoFilter(sheet, ref, refRange, hCol, options)
}
// autoFilter provides a function to extract the tokens from the filter
// expression. The tokens are mainly non-whitespace groups.
-func (f *File) autoFilter(sheet, ref string, refRange, col int, formatSet *formatAutoFilter) error {
+func (f *File) autoFilter(sheet, ref string, refRange, col int, opts *autoFilterOptions) error {
ws, err := f.workSheetReader(sheet)
if err != nil {
return err
@@ -346,28 +346,28 @@ func (f *File) autoFilter(sheet, ref string, refRange, col int, formatSet *forma
Ref: ref,
}
ws.AutoFilter = filter
- if formatSet.Column == "" || formatSet.Expression == "" {
+ if opts.Column == "" || opts.Expression == "" {
return nil
}
- fsCol, err := ColumnNameToNumber(formatSet.Column)
+ fsCol, err := ColumnNameToNumber(opts.Column)
if err != nil {
return err
}
offset := fsCol - col
if offset < 0 || offset > refRange {
- return fmt.Errorf("incorrect index of column '%s'", formatSet.Column)
+ return fmt.Errorf("incorrect index of column '%s'", opts.Column)
}
filter.FilterColumn = append(filter.FilterColumn, &xlsxFilterColumn{
ColID: offset,
})
re := regexp.MustCompile(`"(?:[^"]|"")*"|\S+`)
- token := re.FindAllString(formatSet.Expression, -1)
+ token := re.FindAllString(opts.Expression, -1)
if len(token) != 3 && len(token) != 7 {
- return fmt.Errorf("incorrect number of tokens in criteria '%s'", formatSet.Expression)
+ return fmt.Errorf("incorrect number of tokens in criteria '%s'", opts.Expression)
}
- expressions, tokens, err := f.parseFilterExpression(formatSet.Expression, token)
+ expressions, tokens, err := f.parseFilterExpression(opts.Expression, token)
if err != nil {
return err
}