|
|
@ -1,3 +1,11 @@
|
|
|
|
|
|
|
|
// Package excelize providing a set of functions that allow you to write to
|
|
|
|
|
|
|
|
// and read from XLSX files. Support reads and writes XLSX file generated by
|
|
|
|
|
|
|
|
// Microsoft Excel™ 2007 and later. Support save file without losing original
|
|
|
|
|
|
|
|
// charts of XLSX. This library needs Go version 1.8 or later.
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Copyright 2016 - 2018 The excelize Authors. All rights reserved. Use of
|
|
|
|
|
|
|
|
// this source code is governed by a BSD-style license that can be found in
|
|
|
|
|
|
|
|
// the LICENSE file.
|
|
|
|
package excelize
|
|
|
|
package excelize
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
@ -282,7 +290,7 @@ func (f *File) autoFilter(sheet, ref string, refRange, hxAxis int, formatSet *fo
|
|
|
|
col := TitleToNumber(formatSet.Column)
|
|
|
|
col := TitleToNumber(formatSet.Column)
|
|
|
|
offset := col - hxAxis
|
|
|
|
offset := col - hxAxis
|
|
|
|
if offset < 0 || offset > refRange {
|
|
|
|
if offset < 0 || offset > refRange {
|
|
|
|
return fmt.Errorf("Incorrect index of column '%s'", formatSet.Column)
|
|
|
|
return fmt.Errorf("incorrect index of column '%s'", formatSet.Column)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
filter.FilterColumn = &xlsxFilterColumn{
|
|
|
|
filter.FilterColumn = &xlsxFilterColumn{
|
|
|
|
ColID: offset,
|
|
|
|
ColID: offset,
|
|
|
@ -290,7 +298,7 @@ func (f *File) autoFilter(sheet, ref string, refRange, hxAxis int, formatSet *fo
|
|
|
|
re := regexp.MustCompile(`"(?:[^"]|"")*"|\S+`)
|
|
|
|
re := regexp.MustCompile(`"(?:[^"]|"")*"|\S+`)
|
|
|
|
token := re.FindAllString(formatSet.Expression, -1)
|
|
|
|
token := re.FindAllString(formatSet.Expression, -1)
|
|
|
|
if len(token) != 3 && len(token) != 7 {
|
|
|
|
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'", formatSet.Expression)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
expressions, tokens, err := f.parseFilterExpression(formatSet.Expression, token)
|
|
|
|
expressions, tokens, err := f.parseFilterExpression(formatSet.Expression, token)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -415,7 +423,7 @@ func (f *File) parseFilterTokens(expression string, tokens []string) ([]int, str
|
|
|
|
operator, ok := operators[strings.ToLower(tokens[1])]
|
|
|
|
operator, ok := operators[strings.ToLower(tokens[1])]
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
// Convert the operator from a number to a descriptive string.
|
|
|
|
// Convert the operator from a number to a descriptive string.
|
|
|
|
return []int{}, "", fmt.Errorf("Unknown operator: %s", tokens[1])
|
|
|
|
return []int{}, "", fmt.Errorf("unknown operator: %s", tokens[1])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
token := tokens[2]
|
|
|
|
token := tokens[2]
|
|
|
|
// Special handling for Blanks/NonBlanks.
|
|
|
|
// Special handling for Blanks/NonBlanks.
|
|
|
@ -423,7 +431,7 @@ func (f *File) parseFilterTokens(expression string, tokens []string) ([]int, str
|
|
|
|
if re {
|
|
|
|
if re {
|
|
|
|
// Only allow Equals or NotEqual in this context.
|
|
|
|
// Only allow Equals or NotEqual in this context.
|
|
|
|
if operator != 2 && operator != 5 {
|
|
|
|
if operator != 2 && operator != 5 {
|
|
|
|
return []int{operator}, token, fmt.Errorf("The operator '%s' in expression '%s' is not valid in relation to Blanks/NonBlanks'", tokens[1], expression)
|
|
|
|
return []int{operator}, token, fmt.Errorf("the operator '%s' in expression '%s' is not valid in relation to Blanks/NonBlanks'", tokens[1], expression)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
token = strings.ToLower(token)
|
|
|
|
token = strings.ToLower(token)
|
|
|
|
// The operator should always be 2 (=) to flag a "simple" equality in
|
|
|
|
// The operator should always be 2 (=) to flag a "simple" equality in
|
|
|
|