2023-01-02 11:47:31 +08:00
|
|
|
// Copyright 2016 - 2023 The excelize Authors. All rights reserved. Use of
|
2018-09-14 00:44:23 +08:00
|
|
|
// this source code is governed by a BSD-style license that can be found in
|
|
|
|
// the LICENSE file.
|
|
|
|
//
|
2022-02-17 00:09:11 +08:00
|
|
|
// Package excelize providing a set of functions that allow you to write to and
|
|
|
|
// read from XLAM / XLSM / XLSX / XLTM / XLTX files. Supports reading and
|
|
|
|
// writing spreadsheet documents generated by Microsoft Excel™ 2007 and later.
|
|
|
|
// Supports complex components by high compatibility, and provided streaming
|
|
|
|
// API for generating or reading data from a worksheet with huge amounts of
|
2023-01-02 11:47:31 +08:00
|
|
|
// data. This library needs Go version 1.16 or later.
|
2018-09-14 00:58:48 +08:00
|
|
|
|
2017-04-28 15:49:41 +08:00
|
|
|
package excelize
|
|
|
|
|
|
|
|
import (
|
2023-04-17 08:48:30 +08:00
|
|
|
"bytes"
|
2017-04-28 15:49:41 +08:00
|
|
|
"encoding/xml"
|
2017-06-08 11:11:11 +08:00
|
|
|
"fmt"
|
2023-04-17 08:48:30 +08:00
|
|
|
"io"
|
2017-06-08 11:11:11 +08:00
|
|
|
"regexp"
|
2017-04-28 15:49:41 +08:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2023-02-13 13:28:02 +08:00
|
|
|
"unicode"
|
|
|
|
"unicode/utf8"
|
2017-04-28 15:49:41 +08:00
|
|
|
)
|
|
|
|
|
2023-04-23 18:00:31 +08:00
|
|
|
var (
|
|
|
|
expressionFormat = regexp.MustCompile(`"(?:[^"]|"")*"|\S+`)
|
|
|
|
conditionFormat = regexp.MustCompile(`(or|\|\|)`)
|
|
|
|
blankFormat = regexp.MustCompile("blanks|nonblanks")
|
|
|
|
matchFormat = regexp.MustCompile("[*?]")
|
|
|
|
)
|
|
|
|
|
This closes #1358, made a refactor with breaking changes, see details:
This made a refactor with breaking changes:
Motivation and Context
When I decided to add set horizontal centered support for this library to resolve #1358, the reason I made this huge breaking change was:
- There are too many exported types for set sheet view, properties, and format properties, although a function using the functional options pattern can be optimized by returning an anonymous function, these types or property set or get function has no binding categorization, so I change these functions like `SetAppProps` to accept a pointer of options structure.
- Users can not easily find out which properties should be in the `SetSheetPrOptions` or `SetSheetFormatPr` categories
- Nested properties cannot proceed modify easily
Introduce 5 new export data types:
`HeaderFooterOptions`, `PageLayoutMarginsOptions`, `PageLayoutOptions`, `SheetPropsOptions`, and `ViewOptions`
Rename 4 exported data types:
- Rename `PivotTableOption` to `PivotTableOptions`
- Rename `FormatHeaderFooter` to `HeaderFooterOptions`
- Rename `FormatSheetProtection` to `SheetProtectionOptions`
- Rename `SparklineOption` to `SparklineOptions`
Remove 54 exported types:
`AutoPageBreaks`, `BaseColWidth`, `BlackAndWhite`, `CodeName`, `CustomHeight`, `Date1904`, `DefaultColWidth`, `DefaultGridColor`, `DefaultRowHeight`, `EnableFormatConditionsCalculation`, `FilterPrivacy`, `FirstPageNumber`, `FitToHeight`, `FitToPage`, `FitToWidth`, `OutlineSummaryBelow`, `PageLayoutOption`, `PageLayoutOptionPtr`, `PageLayoutOrientation`, `PageLayoutPaperSize`, `PageLayoutScale`, `PageMarginBottom`, `PageMarginFooter`, `PageMarginHeader`, `PageMarginLeft`, `PageMarginRight`, `PageMarginsOptions`, `PageMarginsOptionsPtr`, `PageMarginTop`, `Published`, `RightToLeft`, `SheetFormatPrOptions`, `SheetFormatPrOptionsPtr`, `SheetPrOption`, `SheetPrOptionPtr`, `SheetViewOption`, `SheetViewOptionPtr`, `ShowFormulas`, `ShowGridLines`, `ShowRowColHeaders`, `ShowRuler`, `ShowZeros`, `TabColorIndexed`, `TabColorRGB`, `TabColorTheme`, `TabColorTint`, `ThickBottom`, `ThickTop`, `TopLeftCell`, `View`, `WorkbookPrOption`, `WorkbookPrOptionPtr`, `ZeroHeight` and `ZoomScale`
Remove 2 exported constants:
`OrientationPortrait` and `OrientationLandscape`
Change 8 functions:
- Change the `func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error` to `func (f *File) SetPageLayout(sheet string, opts *PageLayoutOptions) error`
- Change the `func (f *File) GetPageLayout(sheet string, opts ...PageLayoutOptionPtr) error` to `func (f *File) GetPageLayout(sheet string) (PageLayoutOptions, error)`
- Change the `func (f *File) SetPageMargins(sheet string, opts ...PageMarginsOptions) error` to `func (f *File) SetPageMargins(sheet string, opts *PageLayoutMarginsOptions) error`
- Change the `func (f *File) GetPageMargins(sheet string, opts ...PageMarginsOptionsPtr) error` to `func (f *File) GetPageMargins(sheet string) (PageLayoutMarginsOptions, error)`
- Change the `func (f *File) SetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOption) error` to `func (f *File) SetSheetView(sheet string, viewIndex int, opts *ViewOptions) error`
- Change the `func (f *File) GetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOptionPtr) error` to `func (f *File) GetSheetView(sheet string, viewIndex int) (ViewOptions, error)`
- Change the `func (f *File) SetWorkbookPrOptions(opts ...WorkbookPrOption) error` to `func (f *File) SetWorkbookProps(opts *WorkbookPropsOptions) error`
- Change the `func (f *File) GetWorkbookPrOptions(opts ...WorkbookPrOptionPtr) error` to `func (f *File) GetWorkbookProps() (WorkbookPropsOptions, error)`
Introduce new function to instead of existing functions:
- New function `func (f *File) SetSheetProps(sheet string, opts *SheetPropsOptions) error` instead of `func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error` and `func (f *File) SetSheetFormatPr(sheet string, opts ...SheetFormatPrOption
2022-09-29 22:00:21 +08:00
|
|
|
// parseTableOptions provides a function to parse the format settings of the
|
2017-04-28 15:49:41 +08:00
|
|
|
// table with default value.
|
2023-03-25 13:30:13 +08:00
|
|
|
func parseTableOptions(opts *Table) (*Table, error) {
|
2023-02-13 13:28:02 +08:00
|
|
|
var err error
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
if opts == nil {
|
2023-03-25 13:30:13 +08:00
|
|
|
return &Table{ShowRowStripes: boolPtr(true)}, err
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
}
|
|
|
|
if opts.ShowRowStripes == nil {
|
|
|
|
opts.ShowRowStripes = boolPtr(true)
|
|
|
|
}
|
2023-04-21 08:51:04 +08:00
|
|
|
if err = checkDefinedName(opts.Name); err != nil {
|
2023-02-13 13:28:02 +08:00
|
|
|
return opts, err
|
|
|
|
}
|
|
|
|
return opts, err
|
2017-04-28 15:49:41 +08:00
|
|
|
}
|
|
|
|
|
2017-09-13 22:17:40 +08:00
|
|
|
// AddTable provides the method to add table in a worksheet by given worksheet
|
2022-09-18 00:07:15 +08:00
|
|
|
// name, range reference and format set. For example, create a table of A1:D5
|
2017-04-28 15:49:41 +08:00
|
|
|
// on Sheet1:
|
|
|
|
//
|
2023-03-25 13:30:13 +08:00
|
|
|
// err := f.AddTable("Sheet1", &excelize.Table{Range: "A1:D5"})
|
2017-04-28 15:49:41 +08:00
|
|
|
//
|
|
|
|
// Create a table of F2:H6 on Sheet2 with format set:
|
|
|
|
//
|
2023-01-02 11:47:31 +08:00
|
|
|
// disable := false
|
2023-03-25 13:30:13 +08:00
|
|
|
// err := f.AddTable("Sheet2", &excelize.Table{
|
|
|
|
// Range: "F2:H6",
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
// Name: "table",
|
|
|
|
// StyleName: "TableStyleMedium2",
|
|
|
|
// ShowFirstColumn: true,
|
|
|
|
// ShowLastColumn: true,
|
|
|
|
// ShowRowStripes: &disable,
|
|
|
|
// ShowColumnStripes: true,
|
|
|
|
// })
|
2017-04-28 15:49:41 +08:00
|
|
|
//
|
2020-02-07 00:25:01 +08:00
|
|
|
// 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
|
|
|
|
// header row data of the table before calling the AddTable function. Multiple
|
2022-09-28 00:04:17 +08:00
|
|
|
// tables range reference that can't have an intersection.
|
2018-05-04 11:20:51 +08:00
|
|
|
//
|
2023-02-13 13:28:02 +08:00
|
|
|
// Name: The name of the table, in the same worksheet name of the table should
|
|
|
|
// be unique, starts with a letter or underscore (_), doesn't include a
|
|
|
|
// space or character, and should be no more than 255 characters
|
2017-04-28 15:49:41 +08:00
|
|
|
//
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
// StyleName: The built-in table style names
|
2017-04-28 15:49:41 +08:00
|
|
|
//
|
2022-08-13 11:21:59 +08:00
|
|
|
// TableStyleLight1 - TableStyleLight21
|
|
|
|
// TableStyleMedium1 - TableStyleMedium28
|
|
|
|
// TableStyleDark1 - TableStyleDark11
|
2023-03-25 13:30:13 +08:00
|
|
|
func (f *File) AddTable(sheet string, table *Table) error {
|
|
|
|
options, err := parseTableOptions(table)
|
2023-02-13 13:28:02 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-04-17 08:48:30 +08:00
|
|
|
var exist bool
|
|
|
|
f.Pkg.Range(func(k, v interface{}) bool {
|
|
|
|
if strings.Contains(k.(string), "xl/tables/table") {
|
|
|
|
var t xlsxTable
|
|
|
|
if err := f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(v.([]byte)))).
|
|
|
|
Decode(&t); err != nil && err != io.EOF {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if exist = t.Name == options.Name; exist {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
if exist {
|
|
|
|
return ErrExistsTableName
|
|
|
|
}
|
2017-04-28 15:49:41 +08:00
|
|
|
// Coordinate conversion, convert C1:B3 to 2,0,1,2.
|
2023-03-25 13:30:13 +08:00
|
|
|
coordinates, err := rangeRefToCoordinates(options.Range)
|
2019-03-23 20:08:06 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
// Correct table reference range, such correct C1:B3 to B1:C3.
|
|
|
|
_ = sortCoordinates(coordinates)
|
2017-04-28 15:49:41 +08:00
|
|
|
tableID := f.countTables() + 1
|
|
|
|
sheetRelationshipsTableXML := "../tables/table" + strconv.Itoa(tableID) + ".xml"
|
2022-06-12 00:19:12 +08:00
|
|
|
tableXML := strings.ReplaceAll(sheetRelationshipsTableXML, "..", "xl")
|
2017-04-28 15:49:41 +08:00
|
|
|
// Add first table for given sheet.
|
2022-07-18 00:21:34 +08:00
|
|
|
sheetXMLPath, _ := f.getSheetXMLPath(sheet)
|
|
|
|
sheetRels := "xl/worksheets/_rels/" + strings.TrimPrefix(sheetXMLPath, "xl/worksheets/") + ".rels"
|
2019-09-16 01:17:35 +08:00
|
|
|
rID := f.addRels(sheetRels, SourceRelationshipTable, sheetRelationshipsTableXML, "")
|
2020-07-18 15:15:16 +08:00
|
|
|
if err = f.addSheetTable(sheet, rID); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
f.addSheetNameSpace(sheet, SourceRelationship)
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
if err = f.addTable(sheet, tableXML, coordinates[0], coordinates[1], coordinates[2], coordinates[3], tableID, options); err != nil {
|
2019-03-23 20:08:06 +08:00
|
|
|
return err
|
|
|
|
}
|
2022-11-13 00:40:04 +08:00
|
|
|
return f.addContentTypePart(tableID, "table")
|
2017-04-28 15:49:41 +08:00
|
|
|
}
|
|
|
|
|
2023-08-23 10:51:11 +08:00
|
|
|
// GetTables provides the method to get all tables in a worksheet by given
|
|
|
|
// worksheet name.
|
|
|
|
func (f *File) GetTables(sheet string) ([]Table, error) {
|
|
|
|
var tables []Table
|
|
|
|
ws, err := f.workSheetReader(sheet)
|
|
|
|
if err != nil {
|
|
|
|
return tables, err
|
|
|
|
}
|
|
|
|
if ws.TableParts == nil {
|
|
|
|
return tables, err
|
|
|
|
}
|
|
|
|
for _, tbl := range ws.TableParts.TableParts {
|
|
|
|
if tbl != nil {
|
|
|
|
target := f.getSheetRelationshipsTargetByID(sheet, tbl.RID)
|
|
|
|
tableXML := strings.ReplaceAll(target, "..", "xl")
|
|
|
|
content, ok := f.Pkg.Load(tableXML)
|
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
var t xlsxTable
|
|
|
|
if err := f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(content.([]byte)))).
|
|
|
|
Decode(&t); err != nil && err != io.EOF {
|
|
|
|
return tables, err
|
|
|
|
}
|
|
|
|
table := Table{
|
|
|
|
rID: tbl.RID,
|
2023-09-16 12:21:11 +08:00
|
|
|
tID: t.ID,
|
2023-08-23 10:51:11 +08:00
|
|
|
Range: t.Ref,
|
|
|
|
Name: t.Name,
|
|
|
|
}
|
|
|
|
if t.TableStyleInfo != nil {
|
|
|
|
table.StyleName = t.TableStyleInfo.Name
|
|
|
|
table.ShowColumnStripes = t.TableStyleInfo.ShowColumnStripes
|
|
|
|
table.ShowFirstColumn = t.TableStyleInfo.ShowFirstColumn
|
|
|
|
table.ShowLastColumn = t.TableStyleInfo.ShowLastColumn
|
|
|
|
table.ShowRowStripes = &t.TableStyleInfo.ShowRowStripes
|
|
|
|
}
|
|
|
|
tables = append(tables, table)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tables, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteTable provides the method to delete table by given table name.
|
|
|
|
func (f *File) DeleteTable(name string) error {
|
|
|
|
if err := checkDefinedName(name); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, sheet := range f.GetSheetList() {
|
|
|
|
tables, err := f.GetTables(sheet)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, table := range tables {
|
|
|
|
if table.Name != name {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
ws, _ := f.workSheetReader(sheet)
|
|
|
|
for i, tbl := range ws.TableParts.TableParts {
|
|
|
|
if tbl.RID == table.rID {
|
|
|
|
ws.TableParts.TableParts = append(ws.TableParts.TableParts[:i], ws.TableParts.TableParts[i+1:]...)
|
|
|
|
f.deleteSheetRelationships(sheet, tbl.RID)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ws.TableParts.Count = len(ws.TableParts.TableParts); ws.TableParts.Count == 0 {
|
|
|
|
ws.TableParts = nil
|
|
|
|
}
|
|
|
|
// Delete cell value in the table header
|
|
|
|
coordinates, err := rangeRefToCoordinates(table.Range)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_ = sortCoordinates(coordinates)
|
|
|
|
for col := coordinates[0]; col <= coordinates[2]; col++ {
|
|
|
|
for row := coordinates[1]; row < coordinates[1]+1; row++ {
|
|
|
|
cell, _ := CoordinatesToCellName(col, row)
|
|
|
|
err = f.SetCellValue(sheet, cell, nil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newNoExistTableError(name)
|
|
|
|
}
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// countTables provides a function to get table files count storage in the
|
|
|
|
// folder xl/tables.
|
2017-04-28 15:49:41 +08:00
|
|
|
func (f *File) countTables() int {
|
|
|
|
count := 0
|
2021-07-05 00:03:56 +08:00
|
|
|
f.Pkg.Range(func(k, v interface{}) bool {
|
2023-09-21 00:06:31 +08:00
|
|
|
if strings.Contains(k.(string), "xl/tables/tableSingleCells") {
|
2023-09-28 08:53:54 +08:00
|
|
|
var cells xlsxSingleXMLCells
|
2023-09-21 00:06:31 +08:00
|
|
|
if err := f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(v.([]byte)))).
|
|
|
|
Decode(&cells); err != nil && err != io.EOF {
|
|
|
|
count++
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
for _, cell := range cells.SingleXmlCell {
|
|
|
|
if count < cell.ID {
|
|
|
|
count = cell.ID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-05 00:03:56 +08:00
|
|
|
if strings.Contains(k.(string), "xl/tables/table") {
|
2023-09-16 12:21:11 +08:00
|
|
|
var t xlsxTable
|
|
|
|
if err := f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(v.([]byte)))).
|
|
|
|
Decode(&t); err != nil && err != io.EOF {
|
|
|
|
count++
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if count < t.ID {
|
|
|
|
count = t.ID
|
|
|
|
}
|
2017-04-28 15:49:41 +08:00
|
|
|
}
|
2021-07-05 00:03:56 +08:00
|
|
|
return true
|
|
|
|
})
|
2017-04-28 15:49:41 +08:00
|
|
|
return count
|
|
|
|
}
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// addSheetTable provides a function to add tablePart element to
|
2017-09-13 22:00:33 +08:00
|
|
|
// xl/worksheets/sheet%d.xml by given worksheet name and relationship index.
|
2020-07-18 15:15:16 +08:00
|
|
|
func (f *File) addSheetTable(sheet string, rID int) error {
|
|
|
|
ws, err := f.workSheetReader(sheet)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-04-28 15:49:41 +08:00
|
|
|
table := &xlsxTablePart{
|
|
|
|
RID: "rId" + strconv.Itoa(rID),
|
|
|
|
}
|
2020-07-18 15:15:16 +08:00
|
|
|
if ws.TableParts == nil {
|
|
|
|
ws.TableParts = &xlsxTableParts{}
|
2017-04-28 15:49:41 +08:00
|
|
|
}
|
2020-07-18 15:15:16 +08:00
|
|
|
ws.TableParts.Count++
|
|
|
|
ws.TableParts.TableParts = append(ws.TableParts.TableParts, table)
|
|
|
|
return err
|
2017-04-28 15:49:41 +08:00
|
|
|
}
|
|
|
|
|
2022-07-16 12:50:13 +08:00
|
|
|
// setTableHeader provides a function to set cells value in header row for the
|
|
|
|
// table.
|
2023-03-04 00:07:04 +08:00
|
|
|
func (f *File) setTableHeader(sheet string, showHeaderRow bool, x1, y1, x2 int) ([]*xlsxTableColumn, error) {
|
2022-07-16 12:50:13 +08:00
|
|
|
var (
|
|
|
|
tableColumns []*xlsxTableColumn
|
|
|
|
idx int
|
|
|
|
)
|
2019-06-12 08:10:33 +08:00
|
|
|
for i := x1; i <= x2; i++ {
|
2017-04-28 15:49:41 +08:00
|
|
|
idx++
|
2019-06-12 08:10:33 +08:00
|
|
|
cell, err := CoordinatesToCellName(i, y1)
|
2019-03-23 20:08:06 +08:00
|
|
|
if err != nil {
|
2022-07-16 12:50:13 +08:00
|
|
|
return tableColumns, err
|
2019-03-23 20:08:06 +08:00
|
|
|
}
|
|
|
|
name, _ := f.GetCellValue(sheet, cell)
|
2017-04-28 15:49:41 +08:00
|
|
|
if _, err := strconv.Atoi(name); err == nil {
|
2023-03-04 00:07:04 +08:00
|
|
|
if showHeaderRow {
|
|
|
|
_ = f.SetCellStr(sheet, cell, name)
|
|
|
|
}
|
2017-04-28 15:49:41 +08:00
|
|
|
}
|
|
|
|
if name == "" {
|
|
|
|
name = "Column" + strconv.Itoa(idx)
|
2023-03-04 00:07:04 +08:00
|
|
|
if showHeaderRow {
|
|
|
|
_ = f.SetCellStr(sheet, cell, name)
|
|
|
|
}
|
2017-04-28 15:49:41 +08:00
|
|
|
}
|
2022-07-16 12:50:13 +08:00
|
|
|
tableColumns = append(tableColumns, &xlsxTableColumn{
|
2017-04-28 15:49:41 +08:00
|
|
|
ID: idx,
|
|
|
|
Name: name,
|
|
|
|
})
|
|
|
|
}
|
2022-07-16 12:50:13 +08:00
|
|
|
return tableColumns, nil
|
|
|
|
}
|
|
|
|
|
2023-04-21 08:51:04 +08:00
|
|
|
// checkDefinedName check whether there are illegal characters in the defined
|
|
|
|
// name or table name. Verify that the name:
|
2023-02-13 13:28:02 +08:00
|
|
|
// 1. Starts with a letter or underscore (_)
|
|
|
|
// 2. Doesn't include a space or character that isn't allowed
|
2023-04-21 08:51:04 +08:00
|
|
|
func checkDefinedName(name string) error {
|
2023-02-13 13:28:02 +08:00
|
|
|
if utf8.RuneCountInString(name) > MaxFieldLength {
|
2023-04-21 08:51:04 +08:00
|
|
|
return ErrNameLength
|
2023-02-13 13:28:02 +08:00
|
|
|
}
|
|
|
|
for i, c := range name {
|
|
|
|
if string(c) == "_" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if unicode.IsLetter(c) {
|
|
|
|
continue
|
|
|
|
}
|
2023-09-05 19:43:22 +08:00
|
|
|
if i > 0 && (unicode.IsDigit(c) || c == '.') {
|
2023-02-13 13:28:02 +08:00
|
|
|
continue
|
|
|
|
}
|
2023-04-21 08:51:04 +08:00
|
|
|
return newInvalidNameError(name)
|
2023-02-13 13:28:02 +08:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-07-16 12:50:13 +08:00
|
|
|
// addTable provides a function to add table by given worksheet name,
|
2022-09-18 00:07:15 +08:00
|
|
|
// range reference and format set.
|
2023-03-25 13:30:13 +08:00
|
|
|
func (f *File) addTable(sheet, tableXML string, x1, y1, x2, y2, i int, opts *Table) error {
|
2022-07-16 12:50:13 +08:00
|
|
|
// Correct the minimum number of rows, the table at least two lines.
|
|
|
|
if y1 == y2 {
|
|
|
|
y2++
|
|
|
|
}
|
2023-03-04 00:07:04 +08:00
|
|
|
hideHeaderRow := opts != nil && opts.ShowHeaderRow != nil && !*opts.ShowHeaderRow
|
|
|
|
if hideHeaderRow {
|
|
|
|
y1++
|
|
|
|
}
|
2022-09-18 00:07:15 +08:00
|
|
|
// Correct table range reference, such correct C1:B3 to B1:C3.
|
2022-09-28 00:04:17 +08:00
|
|
|
ref, err := f.coordinatesToRangeRef([]int{x1, y1, x2, y2})
|
2022-07-16 12:50:13 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-03-04 00:07:04 +08:00
|
|
|
tableColumns, _ := f.setTableHeader(sheet, !hideHeaderRow, x1, y1, x2)
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
name := opts.Name
|
2018-05-04 11:20:51 +08:00
|
|
|
if name == "" {
|
|
|
|
name = "Table" + strconv.Itoa(i)
|
|
|
|
}
|
2017-04-28 15:49:41 +08:00
|
|
|
t := xlsxTable{
|
2020-07-18 15:15:16 +08:00
|
|
|
XMLNS: NameSpaceSpreadSheet.Value,
|
2017-04-28 15:49:41 +08:00
|
|
|
ID: i,
|
|
|
|
Name: name,
|
|
|
|
DisplayName: name,
|
|
|
|
Ref: ref,
|
|
|
|
AutoFilter: &xlsxAutoFilter{
|
|
|
|
Ref: ref,
|
|
|
|
},
|
|
|
|
TableColumns: &xlsxTableColumns{
|
2022-07-16 12:50:13 +08:00
|
|
|
Count: len(tableColumns),
|
|
|
|
TableColumn: tableColumns,
|
2017-04-28 15:49:41 +08:00
|
|
|
},
|
|
|
|
TableStyleInfo: &xlsxTableStyleInfo{
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
Name: opts.StyleName,
|
This closes #1358, made a refactor with breaking changes, see details:
This made a refactor with breaking changes:
Motivation and Context
When I decided to add set horizontal centered support for this library to resolve #1358, the reason I made this huge breaking change was:
- There are too many exported types for set sheet view, properties, and format properties, although a function using the functional options pattern can be optimized by returning an anonymous function, these types or property set or get function has no binding categorization, so I change these functions like `SetAppProps` to accept a pointer of options structure.
- Users can not easily find out which properties should be in the `SetSheetPrOptions` or `SetSheetFormatPr` categories
- Nested properties cannot proceed modify easily
Introduce 5 new export data types:
`HeaderFooterOptions`, `PageLayoutMarginsOptions`, `PageLayoutOptions`, `SheetPropsOptions`, and `ViewOptions`
Rename 4 exported data types:
- Rename `PivotTableOption` to `PivotTableOptions`
- Rename `FormatHeaderFooter` to `HeaderFooterOptions`
- Rename `FormatSheetProtection` to `SheetProtectionOptions`
- Rename `SparklineOption` to `SparklineOptions`
Remove 54 exported types:
`AutoPageBreaks`, `BaseColWidth`, `BlackAndWhite`, `CodeName`, `CustomHeight`, `Date1904`, `DefaultColWidth`, `DefaultGridColor`, `DefaultRowHeight`, `EnableFormatConditionsCalculation`, `FilterPrivacy`, `FirstPageNumber`, `FitToHeight`, `FitToPage`, `FitToWidth`, `OutlineSummaryBelow`, `PageLayoutOption`, `PageLayoutOptionPtr`, `PageLayoutOrientation`, `PageLayoutPaperSize`, `PageLayoutScale`, `PageMarginBottom`, `PageMarginFooter`, `PageMarginHeader`, `PageMarginLeft`, `PageMarginRight`, `PageMarginsOptions`, `PageMarginsOptionsPtr`, `PageMarginTop`, `Published`, `RightToLeft`, `SheetFormatPrOptions`, `SheetFormatPrOptionsPtr`, `SheetPrOption`, `SheetPrOptionPtr`, `SheetViewOption`, `SheetViewOptionPtr`, `ShowFormulas`, `ShowGridLines`, `ShowRowColHeaders`, `ShowRuler`, `ShowZeros`, `TabColorIndexed`, `TabColorRGB`, `TabColorTheme`, `TabColorTint`, `ThickBottom`, `ThickTop`, `TopLeftCell`, `View`, `WorkbookPrOption`, `WorkbookPrOptionPtr`, `ZeroHeight` and `ZoomScale`
Remove 2 exported constants:
`OrientationPortrait` and `OrientationLandscape`
Change 8 functions:
- Change the `func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error` to `func (f *File) SetPageLayout(sheet string, opts *PageLayoutOptions) error`
- Change the `func (f *File) GetPageLayout(sheet string, opts ...PageLayoutOptionPtr) error` to `func (f *File) GetPageLayout(sheet string) (PageLayoutOptions, error)`
- Change the `func (f *File) SetPageMargins(sheet string, opts ...PageMarginsOptions) error` to `func (f *File) SetPageMargins(sheet string, opts *PageLayoutMarginsOptions) error`
- Change the `func (f *File) GetPageMargins(sheet string, opts ...PageMarginsOptionsPtr) error` to `func (f *File) GetPageMargins(sheet string) (PageLayoutMarginsOptions, error)`
- Change the `func (f *File) SetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOption) error` to `func (f *File) SetSheetView(sheet string, viewIndex int, opts *ViewOptions) error`
- Change the `func (f *File) GetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOptionPtr) error` to `func (f *File) GetSheetView(sheet string, viewIndex int) (ViewOptions, error)`
- Change the `func (f *File) SetWorkbookPrOptions(opts ...WorkbookPrOption) error` to `func (f *File) SetWorkbookProps(opts *WorkbookPropsOptions) error`
- Change the `func (f *File) GetWorkbookPrOptions(opts ...WorkbookPrOptionPtr) error` to `func (f *File) GetWorkbookProps() (WorkbookPropsOptions, error)`
Introduce new function to instead of existing functions:
- New function `func (f *File) SetSheetProps(sheet string, opts *SheetPropsOptions) error` instead of `func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error` and `func (f *File) SetSheetFormatPr(sheet string, opts ...SheetFormatPrOption
2022-09-29 22:00:21 +08:00
|
|
|
ShowFirstColumn: opts.ShowFirstColumn,
|
|
|
|
ShowLastColumn: opts.ShowLastColumn,
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
ShowRowStripes: *opts.ShowRowStripes,
|
This closes #1358, made a refactor with breaking changes, see details:
This made a refactor with breaking changes:
Motivation and Context
When I decided to add set horizontal centered support for this library to resolve #1358, the reason I made this huge breaking change was:
- There are too many exported types for set sheet view, properties, and format properties, although a function using the functional options pattern can be optimized by returning an anonymous function, these types or property set or get function has no binding categorization, so I change these functions like `SetAppProps` to accept a pointer of options structure.
- Users can not easily find out which properties should be in the `SetSheetPrOptions` or `SetSheetFormatPr` categories
- Nested properties cannot proceed modify easily
Introduce 5 new export data types:
`HeaderFooterOptions`, `PageLayoutMarginsOptions`, `PageLayoutOptions`, `SheetPropsOptions`, and `ViewOptions`
Rename 4 exported data types:
- Rename `PivotTableOption` to `PivotTableOptions`
- Rename `FormatHeaderFooter` to `HeaderFooterOptions`
- Rename `FormatSheetProtection` to `SheetProtectionOptions`
- Rename `SparklineOption` to `SparklineOptions`
Remove 54 exported types:
`AutoPageBreaks`, `BaseColWidth`, `BlackAndWhite`, `CodeName`, `CustomHeight`, `Date1904`, `DefaultColWidth`, `DefaultGridColor`, `DefaultRowHeight`, `EnableFormatConditionsCalculation`, `FilterPrivacy`, `FirstPageNumber`, `FitToHeight`, `FitToPage`, `FitToWidth`, `OutlineSummaryBelow`, `PageLayoutOption`, `PageLayoutOptionPtr`, `PageLayoutOrientation`, `PageLayoutPaperSize`, `PageLayoutScale`, `PageMarginBottom`, `PageMarginFooter`, `PageMarginHeader`, `PageMarginLeft`, `PageMarginRight`, `PageMarginsOptions`, `PageMarginsOptionsPtr`, `PageMarginTop`, `Published`, `RightToLeft`, `SheetFormatPrOptions`, `SheetFormatPrOptionsPtr`, `SheetPrOption`, `SheetPrOptionPtr`, `SheetViewOption`, `SheetViewOptionPtr`, `ShowFormulas`, `ShowGridLines`, `ShowRowColHeaders`, `ShowRuler`, `ShowZeros`, `TabColorIndexed`, `TabColorRGB`, `TabColorTheme`, `TabColorTint`, `ThickBottom`, `ThickTop`, `TopLeftCell`, `View`, `WorkbookPrOption`, `WorkbookPrOptionPtr`, `ZeroHeight` and `ZoomScale`
Remove 2 exported constants:
`OrientationPortrait` and `OrientationLandscape`
Change 8 functions:
- Change the `func (f *File) SetPageLayout(sheet string, opts ...PageLayoutOption) error` to `func (f *File) SetPageLayout(sheet string, opts *PageLayoutOptions) error`
- Change the `func (f *File) GetPageLayout(sheet string, opts ...PageLayoutOptionPtr) error` to `func (f *File) GetPageLayout(sheet string) (PageLayoutOptions, error)`
- Change the `func (f *File) SetPageMargins(sheet string, opts ...PageMarginsOptions) error` to `func (f *File) SetPageMargins(sheet string, opts *PageLayoutMarginsOptions) error`
- Change the `func (f *File) GetPageMargins(sheet string, opts ...PageMarginsOptionsPtr) error` to `func (f *File) GetPageMargins(sheet string) (PageLayoutMarginsOptions, error)`
- Change the `func (f *File) SetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOption) error` to `func (f *File) SetSheetView(sheet string, viewIndex int, opts *ViewOptions) error`
- Change the `func (f *File) GetSheetViewOptions(sheet string, viewIndex int, opts ...SheetViewOptionPtr) error` to `func (f *File) GetSheetView(sheet string, viewIndex int) (ViewOptions, error)`
- Change the `func (f *File) SetWorkbookPrOptions(opts ...WorkbookPrOption) error` to `func (f *File) SetWorkbookProps(opts *WorkbookPropsOptions) error`
- Change the `func (f *File) GetWorkbookPrOptions(opts ...WorkbookPrOptionPtr) error` to `func (f *File) GetWorkbookProps() (WorkbookPropsOptions, error)`
Introduce new function to instead of existing functions:
- New function `func (f *File) SetSheetProps(sheet string, opts *SheetPropsOptions) error` instead of `func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error` and `func (f *File) SetSheetFormatPr(sheet string, opts ...SheetFormatPrOption
2022-09-29 22:00:21 +08:00
|
|
|
ShowColumnStripes: opts.ShowColumnStripes,
|
2017-04-28 15:49:41 +08:00
|
|
|
},
|
|
|
|
}
|
2023-03-04 00:07:04 +08:00
|
|
|
if hideHeaderRow {
|
|
|
|
t.AutoFilter = nil
|
|
|
|
t.HeaderRowCount = intPtr(0)
|
|
|
|
}
|
2023-09-16 12:21:11 +08:00
|
|
|
table, err := xml.Marshal(t)
|
2018-05-07 16:12:51 +08:00
|
|
|
f.saveFileList(tableXML, table)
|
2023-09-16 12:21:11 +08:00
|
|
|
return err
|
2017-04-28 15:49:41 +08:00
|
|
|
}
|
2017-06-08 11:11:11 +08:00
|
|
|
|
|
|
|
// AutoFilter provides the method to add auto filter in a worksheet by given
|
2022-09-18 00:07:15 +08:00
|
|
|
// worksheet name, range reference and settings. An auto filter in Excel is a
|
2018-05-03 10:01:41 +08:00
|
|
|
// way of filtering a 2D range of data based on some simple criteria. For
|
2022-09-18 00:07:15 +08:00
|
|
|
// example applying an auto filter to a cell range A1:D4 in the Sheet1:
|
2017-06-08 11:11:11 +08:00
|
|
|
//
|
2023-03-04 00:07:04 +08:00
|
|
|
// err := f.AutoFilter("Sheet1", "A1:D4", []excelize.AutoFilterOptions{})
|
2017-06-08 11:11:11 +08:00
|
|
|
//
|
2022-09-18 00:07:15 +08:00
|
|
|
// Filter data in an auto filter:
|
2017-06-08 11:11:11 +08:00
|
|
|
//
|
2023-03-04 00:07:04 +08:00
|
|
|
// err := f.AutoFilter("Sheet1", "A1:D4", []excelize.AutoFilterOptions{
|
|
|
|
// {Column: "B", Expression: "x != blanks"},
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
// })
|
2017-06-08 11:11:11 +08:00
|
|
|
//
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
// Column defines the filter columns in an auto filter range based on simple
|
2017-06-14 15:01:49 +08:00
|
|
|
// criteria
|
2017-06-08 11:11:11 +08:00
|
|
|
//
|
2018-05-03 10:01:41 +08:00
|
|
|
// It isn't sufficient to just specify the filter condition. You must also
|
|
|
|
// hide any rows that don't match the filter condition. Rows are hidden using
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
// the SetRowVisible function. Excelize can't filter rows automatically since
|
2018-05-03 10:01:41 +08:00
|
|
|
// this isn't part of the file format.
|
2017-06-08 11:11:11 +08:00
|
|
|
//
|
|
|
|
// Setting a filter criteria for a column:
|
|
|
|
//
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
// Expression defines the conditions, the following operators are available
|
2018-05-03 10:01:41 +08:00
|
|
|
// for setting the filter criteria:
|
2017-06-08 11:11:11 +08:00
|
|
|
//
|
2022-08-13 11:21:59 +08:00
|
|
|
// ==
|
|
|
|
// !=
|
|
|
|
// >
|
|
|
|
// <
|
|
|
|
// >=
|
|
|
|
// <=
|
|
|
|
// and
|
|
|
|
// or
|
2017-06-08 11:11:11 +08:00
|
|
|
//
|
2018-05-03 10:01:41 +08:00
|
|
|
// An expression can comprise a single statement or two statements separated
|
|
|
|
// by the 'and' and 'or' operators. For example:
|
2017-06-08 11:11:11 +08:00
|
|
|
//
|
2022-08-13 11:21:59 +08:00
|
|
|
// x < 2000
|
|
|
|
// x > 2000
|
|
|
|
// x == 2000
|
|
|
|
// x > 2000 and x < 5000
|
|
|
|
// x == 2000 or x == 5000
|
2017-06-08 11:11:11 +08:00
|
|
|
//
|
2017-06-14 15:01:49 +08:00
|
|
|
// Filtering of blank or non-blank data can be achieved by using a value of
|
|
|
|
// Blanks or NonBlanks in the expression:
|
2017-06-08 11:11:11 +08:00
|
|
|
//
|
2022-08-13 11:21:59 +08:00
|
|
|
// x == Blanks
|
|
|
|
// x == NonBlanks
|
2017-06-08 11:11:11 +08:00
|
|
|
//
|
|
|
|
// Excel also allows some simple string matching operations:
|
|
|
|
//
|
2022-08-13 11:21:59 +08:00
|
|
|
// 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
|
2023-05-30 00:14:44 +08:00
|
|
|
// x != *b* // doesn't contain b
|
2017-06-08 11:11:11 +08:00
|
|
|
//
|
2017-06-14 15:01:49 +08:00
|
|
|
// You can also use '*' to match any character or number and '?' to match any
|
|
|
|
// single character or number. No other regular expression quantifier is
|
|
|
|
// supported by Excel's filters. Excel's regular expression characters can be
|
|
|
|
// escaped using '~'.
|
2017-06-08 11:11:11 +08:00
|
|
|
//
|
2017-06-14 15:01:49 +08:00
|
|
|
// The placeholder variable x in the above examples can be replaced by any
|
|
|
|
// simple string. The actual placeholder name is ignored internally so the
|
|
|
|
// following are all equivalent:
|
2017-06-08 11:11:11 +08:00
|
|
|
//
|
2022-08-13 11:21:59 +08:00
|
|
|
// x < 2000
|
|
|
|
// col < 2000
|
|
|
|
// Price < 2000
|
2023-03-04 00:07:04 +08:00
|
|
|
func (f *File) AutoFilter(sheet, rangeRef string, opts []AutoFilterOptions) error {
|
2023-01-02 11:47:31 +08:00
|
|
|
coordinates, err := rangeRefToCoordinates(rangeRef)
|
2019-03-23 20:08:06 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
Breaking change: changed the function signature for 11 exported functions
* Change
`func (f *File) NewConditionalStyle(style string) (int, error)`
to
`func (f *File) NewConditionalStyle(style *Style) (int, error)`
* Change
`func (f *File) NewStyle(style interface{}) (int, error)`
to
`func (f *File) NewStyle(style *Style) (int, error)`
* Change
`func (f *File) AddChart(sheet, cell, opts string, combo ...string) error`
to
`func (f *File) AddChart(sheet, cell string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddChartSheet(sheet, opts string, combo ...string) error`
to
`func (f *File) AddChartSheet(sheet string, chart *ChartOptions, combo ...*ChartOptions) error`
* Change
`func (f *File) AddShape(sheet, cell, opts string) error`
to
`func (f *File) AddShape(sheet, cell string, opts *Shape) error`
* Change
`func (f *File) AddPictureFromBytes(sheet, cell, opts, name, extension string, file []byte) error`
to
`func (f *File) AddPictureFromBytes(sheet, cell, name, extension string, file []byte, opts *PictureOptions) error`
* Change
`func (f *File) AddTable(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AddTable(sheet, reference string, opts *TableOptions) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) AutoFilter(sheet, hCell, vCell, opts string) error`
to
`func (f *File) AutoFilter(sheet, reference string, opts *AutoFilterOptions) error`
* Change
`func (f *File) SetPanes(sheet, panes string) error`
to
`func (f *File) SetPanes(sheet string, panes *Panes) error`
* Change
`func (sw *StreamWriter) AddTable(hCell, vCell, opts string) error`
to
`func (sw *StreamWriter) AddTable(reference string, opts *TableOptions) error`
* Change
`func (f *File) SetConditionalFormat(sheet, reference, opts string) error`
to
`func (f *File) SetConditionalFormat(sheet, reference string, opts []ConditionalFormatOptions) error`
* Add exported types:
* AutoFilterListOptions
* AutoFilterOptions
* Chart
* ChartAxis
* ChartDimension
* ChartLegend
* ChartLine
* ChartMarker
* ChartPlotArea
* ChartSeries
* ChartTitle
* ConditionalFormatOptions
* PaneOptions
* Panes
* PictureOptions
* Shape
* ShapeColor
* ShapeLine
* ShapeParagraph
* TableOptions
* This added support for set sheet visible as very hidden
* Return error when missing required parameters for set defined name
* Update unit test and comments
2022-12-30 00:50:08 +08:00
|
|
|
_ = sortCoordinates(coordinates)
|
|
|
|
// Correct reference range, such correct C1:B3 to B1:C3.
|
|
|
|
ref, _ := f.coordinatesToRangeRef(coordinates, true)
|
2022-11-13 00:40:04 +08:00
|
|
|
wb, err := f.workbookReader()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
This closes #1425, breaking changes for sheet name (#1426)
- Checking and return error for invalid sheet name instead of trim invalid characters
- Add error return for the 4 functions: `DeleteSheet`, `GetSheetIndex`, `GetSheetVisible` and `SetSheetName`
- Export new error 4 constants: `ErrSheetNameBlank`, `ErrSheetNameInvalid`, `ErrSheetNameLength` and `ErrSheetNameSingleQuote`
- Rename exported error constant `ErrExistsWorksheet` to `ErrExistsSheet`
- Update unit tests for 90 functions: `AddChart`, `AddChartSheet`, `AddComment`, `AddDataValidation`, `AddPicture`, `AddPictureFromBytes`, `AddPivotTable`, `AddShape`, `AddSparkline`, `AddTable`, `AutoFilter`, `CalcCellValue`, `Cols`, `DeleteChart`, `DeleteComment`, `DeleteDataValidation`, `DeletePicture`, `DeleteSheet`, `DuplicateRow`, `DuplicateRowTo`, `GetCellFormula`, `GetCellHyperLink`, `GetCellRichText`, `GetCellStyle`, `GetCellType`, `GetCellValue`, `GetColOutlineLevel`, `GetCols`, `GetColStyle`, `GetColVisible`, `GetColWidth`, `GetConditionalFormats`, `GetDataValidations`, `GetMergeCells`, `GetPageLayout`, `GetPageMargins`, `GetPicture`, `GetRowHeight`, `GetRowOutlineLevel`, `GetRows`, `GetRowVisible`, `GetSheetIndex`, `GetSheetProps`, `GetSheetVisible`, `GroupSheets`, `InsertCol`, `InsertPageBreak`, `InsertRows`, `MergeCell`, `NewSheet`, `NewStreamWriter`, `ProtectSheet`, `RemoveCol`, `RemovePageBreak`, `RemoveRow`, `Rows`, `SearchSheet`, `SetCellBool`, `SetCellDefault`, `SetCellFloat`, `SetCellFormula`, `SetCellHyperLink`, `SetCellInt`, `SetCellRichText`, `SetCellStr`, `SetCellStyle`, `SetCellValue`, `SetColOutlineLevel`, `SetColStyle`, `SetColVisible`, `SetColWidth`, `SetConditionalFormat`, `SetHeaderFooter`, `SetPageLayout`, `SetPageMargins`, `SetPanes`, `SetRowHeight`, `SetRowOutlineLevel`, `SetRowStyle`, `SetRowVisible`, `SetSheetBackground`, `SetSheetBackgroundFromBytes`, `SetSheetCol`, `SetSheetName`, `SetSheetProps`, `SetSheetRow`, `SetSheetVisible`, `UnmergeCell`, `UnprotectSheet` and
`UnsetConditionalFormat`
- Update documentation of the set style functions
Co-authored-by: guoweikuang <weikuang.guo@shopee.com>
2022-12-23 00:54:40 +08:00
|
|
|
sheetID, err := f.GetSheetIndex(sheet)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-01-16 14:28:35 +08:00
|
|
|
filterRange := fmt.Sprintf("'%s'!%s", sheet, ref)
|
2020-05-14 22:36:00 +08:00
|
|
|
d := xlsxDefinedName{
|
2023-09-08 00:09:41 +08:00
|
|
|
Name: builtInDefinedNames[2],
|
2020-05-14 22:36:00 +08:00
|
|
|
Hidden: true,
|
2020-05-15 14:03:02 +08:00
|
|
|
LocalSheetID: intPtr(sheetID),
|
|
|
|
Data: filterRange,
|
2020-05-14 22:36:00 +08:00
|
|
|
}
|
2020-05-15 14:03:02 +08:00
|
|
|
if wb.DefinedNames == nil {
|
2020-05-14 22:36:00 +08:00
|
|
|
wb.DefinedNames = &xlsxDefinedNames{
|
|
|
|
DefinedName: []xlsxDefinedName{d},
|
|
|
|
}
|
2020-05-15 14:03:02 +08:00
|
|
|
} else {
|
|
|
|
var definedNameExists bool
|
|
|
|
for idx := range wb.DefinedNames.DefinedName {
|
2023-09-09 13:51:00 +08:00
|
|
|
definedName, localSheetID := wb.DefinedNames.DefinedName[idx], 0
|
|
|
|
if definedName.LocalSheetID != nil {
|
|
|
|
localSheetID = *definedName.LocalSheetID
|
|
|
|
}
|
|
|
|
if definedName.Name == builtInDefinedNames[2] && localSheetID == sheetID && definedName.Hidden {
|
2020-05-15 14:03:02 +08:00
|
|
|
wb.DefinedNames.DefinedName[idx].Data = filterRange
|
|
|
|
definedNameExists = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !definedNameExists {
|
|
|
|
wb.DefinedNames.DefinedName = append(wb.DefinedNames.DefinedName, d)
|
|
|
|
}
|
2020-05-14 22:36:00 +08:00
|
|
|
}
|
2023-01-02 11:47:31 +08:00
|
|
|
columns := coordinates[2] - coordinates[0]
|
|
|
|
return f.autoFilter(sheet, ref, columns, coordinates[0], opts)
|
2017-06-08 11:11:11 +08:00
|
|
|
}
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// autoFilter provides a function to extract the tokens from the filter
|
2017-06-08 11:11:11 +08:00
|
|
|
// expression. The tokens are mainly non-whitespace groups.
|
2023-03-04 00:07:04 +08:00
|
|
|
func (f *File) autoFilter(sheet, ref string, columns, col int, opts []AutoFilterOptions) error {
|
2020-11-10 23:48:09 +08:00
|
|
|
ws, err := f.workSheetReader(sheet)
|
2019-04-15 11:22:57 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-11-10 23:48:09 +08:00
|
|
|
if ws.SheetPr != nil {
|
|
|
|
ws.SheetPr.FilterMode = true
|
2017-06-08 11:11:11 +08:00
|
|
|
}
|
2020-11-10 23:48:09 +08:00
|
|
|
ws.SheetPr = &xlsxSheetPr{FilterMode: true}
|
2017-06-08 11:11:11 +08:00
|
|
|
filter := &xlsxAutoFilter{
|
|
|
|
Ref: ref,
|
|
|
|
}
|
2020-11-10 23:48:09 +08:00
|
|
|
ws.AutoFilter = filter
|
2023-03-04 00:07:04 +08:00
|
|
|
for _, opt := range opts {
|
|
|
|
if opt.Column == "" || opt.Expression == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
fsCol, err := ColumnNameToNumber(opt.Column)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
offset := fsCol - col
|
|
|
|
if offset < 0 || offset > columns {
|
2023-09-28 08:53:54 +08:00
|
|
|
return newInvalidAutoFilterColumnError(opt.Column)
|
2023-03-04 00:07:04 +08:00
|
|
|
}
|
|
|
|
fc := &xlsxFilterColumn{ColID: offset}
|
2023-04-23 18:00:31 +08:00
|
|
|
token := expressionFormat.FindAllString(opt.Expression, -1)
|
2023-03-04 00:07:04 +08:00
|
|
|
if len(token) != 3 && len(token) != 7 {
|
2023-09-28 08:53:54 +08:00
|
|
|
return newInvalidAutoFilterExpError(opt.Expression)
|
2023-03-04 00:07:04 +08:00
|
|
|
}
|
|
|
|
expressions, tokens, err := f.parseFilterExpression(opt.Expression, token)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
f.writeAutoFilter(fc, expressions, tokens)
|
|
|
|
filter.FilterColumn = append(filter.FilterColumn, fc)
|
2017-06-08 11:11:11 +08:00
|
|
|
}
|
2020-11-10 23:48:09 +08:00
|
|
|
ws.AutoFilter = filter
|
2017-06-08 11:11:11 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// writeAutoFilter provides a function to check for single or double custom
|
|
|
|
// filters as default filters and handle them accordingly.
|
2023-03-04 00:07:04 +08:00
|
|
|
func (f *File) writeAutoFilter(fc *xlsxFilterColumn, exp []int, tokens []string) {
|
2017-06-08 11:11:11 +08:00
|
|
|
if len(exp) == 1 && exp[0] == 2 {
|
|
|
|
// Single equality.
|
Huge refactorig for consistent col/row numbering (#356)
* Huge refactorig for consistent col/row numbering
Started from simply changing ToALphaString()/TitleToNumber() logic and related fixes.
But have to go deeper, do fixes, after do related fixes and again and again.
Major improvements:
1. Tests made stronger again (But still be weak).
2. "Empty" returns for incorrect input replaces with panic.
3. Check for correct col/row/cell naming & addressing by default.
4. Removed huge amount of duplicated code.
5. Removed ToALphaString(), TitleToNumber() and it helpers functions at all,
and replaced with SplitCellName(), JoinCellName(), ColumnNameToNumber(), ColumnNumberToName(), CellNameToCoordinates(), CoordinatesToCellName().
6. Minor fixes for internal variable naming for code readability (ex. col, row for input params, colIdx, rowIdx for slice indexes etc).
* Formatting fixes
2019-03-20 00:14:41 +08:00
|
|
|
var filters []*xlsxFilter
|
2017-06-08 11:11:11 +08:00
|
|
|
filters = append(filters, &xlsxFilter{Val: tokens[0]})
|
2023-03-04 00:07:04 +08:00
|
|
|
fc.Filters = &xlsxFilters{Filter: filters}
|
2023-06-08 09:50:38 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(exp) == 3 && exp[0] == 2 && exp[1] == 1 && exp[2] == 2 {
|
2017-06-08 11:11:11 +08:00
|
|
|
// Double equality with "or" operator.
|
2022-03-24 00:19:30 +08:00
|
|
|
var filters []*xlsxFilter
|
2017-06-08 11:11:11 +08:00
|
|
|
for _, v := range tokens {
|
|
|
|
filters = append(filters, &xlsxFilter{Val: v})
|
|
|
|
}
|
2023-03-04 00:07:04 +08:00
|
|
|
fc.Filters = &xlsxFilters{Filter: filters}
|
2023-06-08 09:50:38 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
// Non default custom filter.
|
|
|
|
expRel, andRel := map[int]int{0: 0, 1: 2}, map[int]bool{0: true, 1: false}
|
|
|
|
for k, v := range tokens {
|
|
|
|
f.writeCustomFilter(fc, exp[expRel[k]], v)
|
|
|
|
if k == 1 {
|
|
|
|
fc.CustomFilters.And = andRel[exp[k]]
|
2017-06-08 11:11:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// writeCustomFilter provides a function to write the <customFilter> element.
|
2023-03-04 00:07:04 +08:00
|
|
|
func (f *File) writeCustomFilter(fc *xlsxFilterColumn, operator int, val string) {
|
2017-06-08 11:11:11 +08:00
|
|
|
operators := map[int]string{
|
|
|
|
1: "lessThan",
|
|
|
|
2: "equal",
|
|
|
|
3: "lessThanOrEqual",
|
|
|
|
4: "greaterThan",
|
|
|
|
5: "notEqual",
|
|
|
|
6: "greaterThanOrEqual",
|
|
|
|
22: "equal",
|
|
|
|
}
|
|
|
|
customFilter := xlsxCustomFilter{
|
|
|
|
Operator: operators[operator],
|
|
|
|
Val: val,
|
|
|
|
}
|
2023-03-04 00:07:04 +08:00
|
|
|
if fc.CustomFilters != nil {
|
|
|
|
fc.CustomFilters.CustomFilter = append(fc.CustomFilters.CustomFilter, &customFilter)
|
2023-06-08 09:50:38 +08:00
|
|
|
return
|
2017-06-08 11:11:11 +08:00
|
|
|
}
|
2023-06-08 09:50:38 +08:00
|
|
|
var customFilters []*xlsxCustomFilter
|
|
|
|
customFilters = append(customFilters, &customFilter)
|
|
|
|
fc.CustomFilters = &xlsxCustomFilters{CustomFilter: customFilters}
|
2017-06-08 11:11:11 +08:00
|
|
|
}
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// parseFilterExpression provides a function to converts the tokens of a
|
|
|
|
// possibly conditional expression into 1 or 2 sub expressions for further
|
|
|
|
// parsing.
|
2017-06-08 11:11:11 +08:00
|
|
|
//
|
|
|
|
// Examples:
|
|
|
|
//
|
2022-08-13 11:21:59 +08:00
|
|
|
// ('x', '==', 2000) -> exp1
|
|
|
|
// ('x', '>', 2000, 'and', 'x', '<', 5000) -> exp1 and exp2
|
2017-06-08 11:11:11 +08:00
|
|
|
func (f *File) parseFilterExpression(expression string, tokens []string) ([]int, []string, error) {
|
2022-03-24 00:19:30 +08:00
|
|
|
var expressions []int
|
|
|
|
var t []string
|
2017-06-08 11:11:11 +08:00
|
|
|
if len(tokens) == 7 {
|
|
|
|
// The number of tokens will be either 3 (for 1 expression) or 7 (for 2
|
|
|
|
// expressions).
|
2023-06-08 09:50:38 +08:00
|
|
|
conditional, c := 0, tokens[3]
|
2023-05-22 09:24:28 +08:00
|
|
|
if conditionFormat.MatchString(c) {
|
2017-06-08 11:11:11 +08:00
|
|
|
conditional = 1
|
|
|
|
}
|
2021-11-17 00:25:36 +08:00
|
|
|
expression1, token1, err := f.parseFilterTokens(expression, tokens[:3])
|
2017-06-08 11:11:11 +08:00
|
|
|
if err != nil {
|
|
|
|
return expressions, t, err
|
|
|
|
}
|
|
|
|
expression2, token2, err := f.parseFilterTokens(expression, tokens[4:7])
|
|
|
|
if err != nil {
|
|
|
|
return expressions, t, err
|
|
|
|
}
|
2023-06-08 09:50:38 +08:00
|
|
|
return []int{expression1[0], conditional, expression2[0]}, []string{token1, token2}, nil
|
|
|
|
}
|
|
|
|
exp, token, err := f.parseFilterTokens(expression, tokens)
|
|
|
|
if err != nil {
|
|
|
|
return expressions, t, err
|
2017-06-08 11:11:11 +08:00
|
|
|
}
|
2023-06-08 09:50:38 +08:00
|
|
|
return exp, []string{token}, nil
|
2017-06-08 11:11:11 +08:00
|
|
|
}
|
|
|
|
|
2018-08-06 10:21:24 +08:00
|
|
|
// parseFilterTokens provides a function to parse the 3 tokens of a filter
|
2017-06-08 11:11:11 +08:00
|
|
|
// expression and return the operator and token.
|
|
|
|
func (f *File) parseFilterTokens(expression string, tokens []string) ([]int, string, error) {
|
|
|
|
operators := map[string]int{
|
|
|
|
"==": 2,
|
|
|
|
"=": 2,
|
|
|
|
"=~": 2,
|
|
|
|
"eq": 2,
|
|
|
|
"!=": 5,
|
|
|
|
"!~": 5,
|
|
|
|
"ne": 5,
|
|
|
|
"<>": 5,
|
|
|
|
"<": 1,
|
|
|
|
"<=": 3,
|
|
|
|
">": 4,
|
|
|
|
">=": 6,
|
|
|
|
}
|
|
|
|
operator, ok := operators[strings.ToLower(tokens[1])]
|
|
|
|
if !ok {
|
|
|
|
// Convert the operator from a number to a descriptive string.
|
2023-06-08 09:50:38 +08:00
|
|
|
return []int{}, "", newUnknownFilterTokenError(tokens[1])
|
2017-06-08 11:11:11 +08:00
|
|
|
}
|
|
|
|
token := tokens[2]
|
|
|
|
// Special handling for Blanks/NonBlanks.
|
2023-05-30 00:14:44 +08:00
|
|
|
re := blankFormat.MatchString(strings.ToLower(token))
|
2017-06-08 11:11:11 +08:00
|
|
|
if re {
|
|
|
|
// Only allow Equals or NotEqual in this context.
|
|
|
|
if operator != 2 && operator != 5 {
|
2023-09-28 08:53:54 +08:00
|
|
|
return []int{operator}, token, newInvalidAutoFilterOperatorError(tokens[1], expression)
|
2017-06-08 11:11:11 +08:00
|
|
|
}
|
|
|
|
token = strings.ToLower(token)
|
|
|
|
// The operator should always be 2 (=) to flag a "simple" equality in
|
|
|
|
// the binary record. Therefore we convert <> to =.
|
|
|
|
if token == "blanks" {
|
|
|
|
if operator == 5 {
|
|
|
|
token = " "
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if operator == 5 {
|
|
|
|
operator = 2
|
|
|
|
token = "blanks"
|
|
|
|
} else {
|
|
|
|
operator = 5
|
|
|
|
token = " "
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-10-14 00:48:16 +08:00
|
|
|
// If the string token contains an Excel match character then change the
|
2017-06-08 11:11:11 +08:00
|
|
|
// operator type to indicate a non "simple" equality.
|
2023-06-08 09:50:38 +08:00
|
|
|
if re = matchFormat.MatchString(token); operator == 2 && re {
|
2017-06-08 11:11:11 +08:00
|
|
|
operator = 22
|
|
|
|
}
|
|
|
|
return []int{operator}, token, nil
|
|
|
|
}
|