summaryrefslogtreecommitdiff
path: root/table.go
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2022-08-13 11:21:59 +0800
committerxuri <xuri.me@gmail.com>2022-08-13 11:21:59 +0800
commit551fb8a9e4b03fe718a339e75aeacc8b5581378a (patch)
tree17e38203f802da690e709072305476b450a620ac /table.go
parent8152bbb2cec76f074dc18c43f3c66bf8abdf9de0 (diff)
This closes #1244 and closes #1314, improving the compatibility with Google Sheet
- Format code with `gofmt`
Diffstat (limited to 'table.go')
-rw-r--r--table.go83
1 files changed, 40 insertions, 43 deletions
diff --git a/table.go b/table.go
index cf9c22a..dc5f441 100644
--- a/table.go
+++ b/table.go
@@ -32,18 +32,18 @@ func parseFormatTableSet(formatSet string) (*formatTable, error) {
// name, coordinate area and format set. For example, create a table of A1:D5
// on Sheet1:
//
-// err := f.AddTable("Sheet1", "A1", "D5", "")
+// err := f.AddTable("Sheet1", "A1", "D5", "")
//
// Create a table of F2:H6 on Sheet2 with format set:
//
-// err := f.AddTable("Sheet2", "F2", "H6", `{
-// "table_name": "table",
-// "table_style": "TableStyleMedium2",
-// "show_first_column": true,
-// "show_last_column": true,
-// "show_row_stripes": false,
-// "show_column_stripes": true
-// }`)
+// err := f.AddTable("Sheet2", "F2", "H6", `{
+// "table_name": "table",
+// "table_style": "TableStyleMedium2",
+// "show_first_column": true,
+// "show_last_column": true,
+// "show_row_stripes": false,
+// "show_column_stripes": true
+// }`)
//
// Note that the table must be at least two lines including the header. The
// header cells must contain strings and must be unique, and must set the
@@ -54,10 +54,9 @@ func parseFormatTableSet(formatSet string) (*formatTable, error) {
//
// table_style: The built-in table style names
//
-// TableStyleLight1 - TableStyleLight21
-// TableStyleMedium1 - TableStyleMedium28
-// TableStyleDark1 - TableStyleDark11
-//
+// TableStyleLight1 - TableStyleLight21
+// TableStyleMedium1 - TableStyleMedium28
+// TableStyleDark1 - TableStyleDark11
func (f *File) AddTable(sheet, hCell, vCell, format string) error {
formatSet, err := parseFormatTableSet(format)
if err != nil {
@@ -216,11 +215,11 @@ func parseAutoFilterSet(formatSet string) (*formatAutoFilter, error) {
// way of filtering a 2D range of data based on some simple criteria. For
// example applying an autofilter to a cell range A1:D4 in the Sheet1:
//
-// err := f.AutoFilter("Sheet1", "A1", "D4", "")
+// err := f.AutoFilter("Sheet1", "A1", "D4", "")
//
// Filter data in an autofilter:
//
-// err := f.AutoFilter("Sheet1", "A1", "D4", `{"column":"B","expression":"x != blanks"}`)
+// err := f.AutoFilter("Sheet1", "A1", "D4", `{"column":"B","expression":"x != blanks"}`)
//
// column defines the filter columns in a autofilter range based on simple
// criteria
@@ -235,38 +234,38 @@ func parseAutoFilterSet(formatSet string) (*formatAutoFilter, error) {
// expression defines the conditions, the following operators are available
// for setting the filter criteria:
//
-// ==
-// !=
-// >
-// <
-// >=
-// <=
-// and
-// or
+// ==
+// !=
+// >
+// <
+// >=
+// <=
+// and
+// or
//
// An expression can comprise a single statement or two statements separated
// by the 'and' and 'or' operators. For example:
//
-// x < 2000
-// x > 2000
-// x == 2000
-// x > 2000 and x < 5000
-// x == 2000 or x == 5000
+// x < 2000
+// x > 2000
+// x == 2000
+// x > 2000 and x < 5000
+// x == 2000 or x == 5000
//
// Filtering of blank or non-blank data can be achieved by using a value of
// Blanks or NonBlanks in the expression:
//
-// x == Blanks
-// x == NonBlanks
+// x == Blanks
+// x == NonBlanks
//
// Excel also allows some simple string matching operations:
//
-// x == b* // begins with b
-// x != b* // doesn't begin with b
-// x == *b // ends with b
-// x != *b // doesn't end with b
-// x == *b* // contains b
-// x != *b* // doesn't contains b
+// x == b* // begins with b
+// x != b* // doesn't begin with b
+// x == *b // ends with b
+// x != *b // doesn't end with b
+// x == *b* // contains b
+// x != *b* // doesn't contains b
//
// You can also use '*' to match any character or number and '?' to match any
// single character or number. No other regular expression quantifier is
@@ -277,10 +276,9 @@ func parseAutoFilterSet(formatSet string) (*formatAutoFilter, error) {
// simple string. The actual placeholder name is ignored internally so the
// following are all equivalent:
//
-// x < 2000
-// col < 2000
-// Price < 2000
-//
+// x < 2000
+// col < 2000
+// Price < 2000
func (f *File) AutoFilter(sheet, hCell, vCell, format string) error {
hCol, hRow, err := CellNameToCoordinates(hCell)
if err != nil {
@@ -436,9 +434,8 @@ func (f *File) writeCustomFilter(filter *xlsxAutoFilter, operator int, val strin
//
// Examples:
//
-// ('x', '==', 2000) -> exp1
-// ('x', '>', 2000, 'and', 'x', '<', 5000) -> exp1 and exp2
-//
+// ('x', '==', 2000) -> exp1
+// ('x', '>', 2000, 'and', 'x', '<', 5000) -> exp1 and exp2
func (f *File) parseFilterExpression(expression string, tokens []string) ([]int, []string, error) {
var expressions []int
var t []string