2019-03-24 13:08:32 +08:00
|
|
|
package excelize
|
|
|
|
|
|
|
|
import (
|
2022-07-16 12:50:13 +08:00
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
2019-03-24 13:08:32 +08:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAdjustMergeCells(t *testing.T) {
|
|
|
|
f := NewFile()
|
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
|
|
|
// Test adjustAutoFilter with illegal cell reference
|
2023-03-25 13:30:13 +08:00
|
|
|
assert.Equal(t, f.adjustMergeCells(&xlsxWorksheet{
|
2019-03-24 13:08:32 +08:00
|
|
|
MergeCells: &xlsxMergeCells{
|
|
|
|
Cells: []*xlsxMergeCell{
|
2019-04-16 10:57:21 +08:00
|
|
|
{
|
2019-03-24 13:08:32 +08:00
|
|
|
Ref: "A:B1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-03-25 13:30:13 +08:00
|
|
|
}, rows, 0, 0), newCellNameToCoordinatesError("A", newInvalidCellNameError("A")))
|
|
|
|
assert.Equal(t, f.adjustMergeCells(&xlsxWorksheet{
|
2019-03-24 13:08:32 +08:00
|
|
|
MergeCells: &xlsxMergeCells{
|
|
|
|
Cells: []*xlsxMergeCell{
|
2019-04-16 10:57:21 +08:00
|
|
|
{
|
2019-03-24 13:08:32 +08:00
|
|
|
Ref: "A1:B",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-03-25 13:30:13 +08:00
|
|
|
}, rows, 0, 0), newCellNameToCoordinatesError("B", newInvalidCellNameError("B")))
|
2019-06-12 08:10:33 +08:00
|
|
|
assert.NoError(t, f.adjustMergeCells(&xlsxWorksheet{
|
|
|
|
MergeCells: &xlsxMergeCells{
|
|
|
|
Cells: []*xlsxMergeCell{
|
|
|
|
{
|
|
|
|
Ref: "A1:B1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, rows, 1, -1))
|
|
|
|
assert.NoError(t, f.adjustMergeCells(&xlsxWorksheet{
|
|
|
|
MergeCells: &xlsxMergeCells{
|
|
|
|
Cells: []*xlsxMergeCell{
|
|
|
|
{
|
|
|
|
Ref: "A1:A2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, columns, 1, -1))
|
2022-10-26 00:04:23 +08:00
|
|
|
assert.NoError(t, f.adjustMergeCells(&xlsxWorksheet{
|
|
|
|
MergeCells: &xlsxMergeCells{
|
|
|
|
Cells: []*xlsxMergeCell{
|
|
|
|
{
|
|
|
|
Ref: "A2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, columns, 1, -1))
|
2021-12-06 22:37:25 +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
|
|
|
// Test adjust merge cells
|
2021-12-06 22:37:25 +08:00
|
|
|
var cases []struct {
|
2022-01-14 00:28:31 +08:00
|
|
|
label string
|
|
|
|
ws *xlsxWorksheet
|
|
|
|
dir adjustDirection
|
|
|
|
num int
|
|
|
|
offset int
|
|
|
|
expect string
|
|
|
|
expectRect []int
|
2021-12-06 22:37:25 +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
|
|
|
// Test adjust merged cell when insert rows and columns
|
2021-12-06 22:37:25 +08:00
|
|
|
cases = []struct {
|
2022-01-14 00:28:31 +08:00
|
|
|
label string
|
|
|
|
ws *xlsxWorksheet
|
|
|
|
dir adjustDirection
|
|
|
|
num int
|
|
|
|
offset int
|
|
|
|
expect string
|
|
|
|
expectRect []int
|
2021-12-06 22:37:25 +08:00
|
|
|
}{
|
|
|
|
{
|
2022-01-09 00:20:42 +08:00
|
|
|
label: "insert row on ref",
|
2021-12-06 22:37:25 +08:00
|
|
|
ws: &xlsxWorksheet{
|
|
|
|
MergeCells: &xlsxMergeCells{
|
|
|
|
Cells: []*xlsxMergeCell{
|
|
|
|
{
|
2022-01-14 00:28:31 +08:00
|
|
|
Ref: "A2:B3",
|
|
|
|
rect: []int{1, 2, 2, 3},
|
2021-12-06 22:37:25 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-14 00:28:31 +08:00
|
|
|
dir: rows,
|
|
|
|
num: 2,
|
|
|
|
offset: 1,
|
|
|
|
expect: "A3:B4",
|
|
|
|
expectRect: []int{1, 3, 2, 4},
|
2021-12-06 22:37:25 +08:00
|
|
|
},
|
|
|
|
{
|
2022-01-09 00:20:42 +08:00
|
|
|
label: "insert row on bottom of ref",
|
2021-12-06 22:37:25 +08:00
|
|
|
ws: &xlsxWorksheet{
|
|
|
|
MergeCells: &xlsxMergeCells{
|
|
|
|
Cells: []*xlsxMergeCell{
|
|
|
|
{
|
2022-01-14 00:28:31 +08:00
|
|
|
Ref: "A2:B3",
|
|
|
|
rect: []int{1, 2, 2, 3},
|
2021-12-06 22:37:25 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-14 00:28:31 +08:00
|
|
|
dir: rows,
|
|
|
|
num: 3,
|
|
|
|
offset: 1,
|
|
|
|
expect: "A2:B4",
|
|
|
|
expectRect: []int{1, 2, 2, 4},
|
2021-12-06 22:37:25 +08:00
|
|
|
},
|
|
|
|
{
|
2022-01-09 00:20:42 +08:00
|
|
|
label: "insert column on the left",
|
2021-12-06 22:37:25 +08:00
|
|
|
ws: &xlsxWorksheet{
|
|
|
|
MergeCells: &xlsxMergeCells{
|
|
|
|
Cells: []*xlsxMergeCell{
|
|
|
|
{
|
2022-01-14 00:28:31 +08:00
|
|
|
Ref: "A2:B3",
|
|
|
|
rect: []int{1, 2, 2, 3},
|
2021-12-06 22:37:25 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-14 00:28:31 +08:00
|
|
|
dir: columns,
|
|
|
|
num: 1,
|
|
|
|
offset: 1,
|
|
|
|
expect: "B2:C3",
|
|
|
|
expectRect: []int{2, 2, 3, 3},
|
2021-12-06 22:37:25 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, c := range cases {
|
|
|
|
assert.NoError(t, f.adjustMergeCells(c.ws, c.dir, c.num, 1))
|
2022-01-09 00:20:42 +08:00
|
|
|
assert.Equal(t, c.expect, c.ws.MergeCells.Cells[0].Ref, c.label)
|
2022-01-14 00:28:31 +08:00
|
|
|
assert.Equal(t, c.expectRect, c.ws.MergeCells.Cells[0].rect, c.label)
|
2021-12-06 22:37:25 +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
|
|
|
// Test adjust merged cells when delete rows and columns
|
2021-12-06 22:37:25 +08:00
|
|
|
cases = []struct {
|
2022-01-14 00:28:31 +08:00
|
|
|
label string
|
|
|
|
ws *xlsxWorksheet
|
|
|
|
dir adjustDirection
|
|
|
|
num int
|
|
|
|
offset int
|
|
|
|
expect string
|
|
|
|
expectRect []int
|
2021-12-06 22:37:25 +08:00
|
|
|
}{
|
|
|
|
{
|
2022-01-09 00:20:42 +08:00
|
|
|
label: "delete row on top of ref",
|
2021-12-06 22:37:25 +08:00
|
|
|
ws: &xlsxWorksheet{
|
|
|
|
MergeCells: &xlsxMergeCells{
|
|
|
|
Cells: []*xlsxMergeCell{
|
|
|
|
{
|
2022-01-14 00:28:31 +08:00
|
|
|
Ref: "A2:B3",
|
|
|
|
rect: []int{1, 2, 2, 3},
|
2021-12-06 22:37:25 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-14 00:28:31 +08:00
|
|
|
dir: rows,
|
|
|
|
num: 2,
|
|
|
|
offset: -1,
|
|
|
|
expect: "A2:B2",
|
|
|
|
expectRect: []int{1, 2, 2, 2},
|
2021-12-06 22:37:25 +08:00
|
|
|
},
|
|
|
|
{
|
2022-01-09 00:20:42 +08:00
|
|
|
label: "delete row on bottom of ref",
|
2021-12-06 22:37:25 +08:00
|
|
|
ws: &xlsxWorksheet{
|
|
|
|
MergeCells: &xlsxMergeCells{
|
|
|
|
Cells: []*xlsxMergeCell{
|
|
|
|
{
|
2022-01-14 00:28:31 +08:00
|
|
|
Ref: "A2:B3",
|
|
|
|
rect: []int{1, 2, 2, 3},
|
2021-12-06 22:37:25 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-14 00:28:31 +08:00
|
|
|
dir: rows,
|
|
|
|
num: 3,
|
|
|
|
offset: -1,
|
|
|
|
expect: "A2:B2",
|
|
|
|
expectRect: []int{1, 2, 2, 2},
|
2021-12-06 22:37:25 +08:00
|
|
|
},
|
|
|
|
{
|
2022-01-09 00:20:42 +08:00
|
|
|
label: "delete column on the ref left",
|
2021-12-06 22:37:25 +08:00
|
|
|
ws: &xlsxWorksheet{
|
|
|
|
MergeCells: &xlsxMergeCells{
|
|
|
|
Cells: []*xlsxMergeCell{
|
|
|
|
{
|
2022-01-14 00:28:31 +08:00
|
|
|
Ref: "A2:B3",
|
|
|
|
rect: []int{1, 2, 2, 3},
|
2021-12-06 22:37:25 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-14 00:28:31 +08:00
|
|
|
dir: columns,
|
|
|
|
num: 1,
|
|
|
|
offset: -1,
|
|
|
|
expect: "A2:A3",
|
|
|
|
expectRect: []int{1, 2, 1, 3},
|
2021-12-06 22:37:25 +08:00
|
|
|
},
|
|
|
|
{
|
2022-01-09 00:20:42 +08:00
|
|
|
label: "delete column on the ref right",
|
2021-12-06 22:37:25 +08:00
|
|
|
ws: &xlsxWorksheet{
|
|
|
|
MergeCells: &xlsxMergeCells{
|
|
|
|
Cells: []*xlsxMergeCell{
|
|
|
|
{
|
2022-01-14 00:28:31 +08:00
|
|
|
Ref: "A2:B3",
|
|
|
|
rect: []int{1, 2, 2, 3},
|
2021-12-06 22:37:25 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-14 00:28:31 +08:00
|
|
|
dir: columns,
|
|
|
|
num: 2,
|
|
|
|
offset: -1,
|
|
|
|
expect: "A2:A3",
|
|
|
|
expectRect: []int{1, 2, 1, 3},
|
2021-12-06 22:37:25 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, c := range cases {
|
|
|
|
assert.NoError(t, f.adjustMergeCells(c.ws, c.dir, c.num, -1))
|
2022-01-09 00:20:42 +08:00
|
|
|
assert.Equal(t, c.expect, c.ws.MergeCells.Cells[0].Ref, c.label)
|
2021-12-06 22:37:25 +08:00
|
|
|
}
|
|
|
|
|
2022-11-12 00:02:11 +08:00
|
|
|
// Test delete one row or column
|
2021-12-06 22:37:25 +08:00
|
|
|
cases = []struct {
|
2022-01-14 00:28:31 +08:00
|
|
|
label string
|
|
|
|
ws *xlsxWorksheet
|
|
|
|
dir adjustDirection
|
|
|
|
num int
|
|
|
|
offset int
|
|
|
|
expect string
|
|
|
|
expectRect []int
|
2021-12-06 22:37:25 +08:00
|
|
|
}{
|
|
|
|
{
|
2022-01-09 00:20:42 +08:00
|
|
|
label: "delete one row ref",
|
2021-12-06 22:37:25 +08:00
|
|
|
ws: &xlsxWorksheet{
|
|
|
|
MergeCells: &xlsxMergeCells{
|
|
|
|
Cells: []*xlsxMergeCell{
|
|
|
|
{
|
2022-01-14 00:28:31 +08:00
|
|
|
Ref: "A1:B1",
|
|
|
|
rect: []int{1, 1, 2, 1},
|
2021-12-06 22:37:25 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
dir: rows,
|
|
|
|
num: 1,
|
|
|
|
offset: -1,
|
|
|
|
},
|
|
|
|
{
|
2022-01-09 00:20:42 +08:00
|
|
|
label: "delete one column ref",
|
2021-12-06 22:37:25 +08:00
|
|
|
ws: &xlsxWorksheet{
|
|
|
|
MergeCells: &xlsxMergeCells{
|
|
|
|
Cells: []*xlsxMergeCell{
|
|
|
|
{
|
2022-01-14 00:28:31 +08:00
|
|
|
Ref: "A1:A2",
|
|
|
|
rect: []int{1, 1, 1, 2},
|
2021-12-06 22:37:25 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
dir: columns,
|
|
|
|
num: 1,
|
|
|
|
offset: -1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, c := range cases {
|
|
|
|
assert.NoError(t, f.adjustMergeCells(c.ws, c.dir, c.num, -1))
|
2023-03-25 13:30:13 +08:00
|
|
|
assert.Len(t, c.ws.MergeCells.Cells, 0, c.label)
|
2021-12-06 22:37:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
f = NewFile()
|
|
|
|
p1, p2 := f.adjustMergeCellsHelper(2, 1, 0, 0)
|
|
|
|
assert.Equal(t, 1, p1)
|
|
|
|
assert.Equal(t, 2, p2)
|
|
|
|
f.deleteMergeCell(nil, -1)
|
2019-03-24 13:08:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAdjustAutoFilter(t *testing.T) {
|
|
|
|
f := NewFile()
|
2020-10-11 00:15:04 +08:00
|
|
|
assert.NoError(t, f.adjustAutoFilter(&xlsxWorksheet{
|
|
|
|
SheetData: xlsxSheetData{
|
|
|
|
Row: []xlsxRow{{Hidden: true, R: 2}},
|
|
|
|
},
|
|
|
|
AutoFilter: &xlsxAutoFilter{
|
|
|
|
Ref: "A1:A3",
|
|
|
|
},
|
|
|
|
}, rows, 1, -1))
|
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
|
|
|
// Test adjustAutoFilter with illegal cell reference
|
2023-03-25 13:30:13 +08:00
|
|
|
assert.Equal(t, f.adjustAutoFilter(&xlsxWorksheet{
|
2019-03-24 13:08:32 +08:00
|
|
|
AutoFilter: &xlsxAutoFilter{
|
|
|
|
Ref: "A:B1",
|
|
|
|
},
|
2023-03-25 13:30:13 +08:00
|
|
|
}, rows, 0, 0), newCellNameToCoordinatesError("A", newInvalidCellNameError("A")))
|
|
|
|
assert.Equal(t, f.adjustAutoFilter(&xlsxWorksheet{
|
2019-03-24 13:08:32 +08:00
|
|
|
AutoFilter: &xlsxAutoFilter{
|
|
|
|
Ref: "A1:B",
|
|
|
|
},
|
2023-03-25 13:30:13 +08:00
|
|
|
}, rows, 0, 0), newCellNameToCoordinatesError("B", newInvalidCellNameError("B")))
|
2019-03-24 13:08:32 +08:00
|
|
|
}
|
|
|
|
|
2022-07-16 12:50:13 +08:00
|
|
|
func TestAdjustTable(t *testing.T) {
|
|
|
|
f, sheetName := NewFile(), "Sheet1"
|
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
|
|
|
for idx, reference := range []string{"B2:C3", "E3:F5", "H5:H8", "J5:K9"} {
|
2023-03-25 13:30:13 +08:00
|
|
|
assert.NoError(t, f.AddTable(sheetName, &Table{
|
|
|
|
Range: reference,
|
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: fmt.Sprintf("table%d", idx),
|
|
|
|
StyleName: "TableStyleMedium2",
|
|
|
|
ShowFirstColumn: true,
|
|
|
|
ShowLastColumn: true,
|
|
|
|
ShowRowStripes: boolPtr(false),
|
|
|
|
ShowColumnStripes: true,
|
|
|
|
}))
|
2022-07-16 12:50:13 +08:00
|
|
|
}
|
|
|
|
assert.NoError(t, f.RemoveRow(sheetName, 2))
|
|
|
|
assert.NoError(t, f.RemoveRow(sheetName, 3))
|
2023-05-23 00:18:55 +08:00
|
|
|
assert.NoError(t, f.RemoveRow(sheetName, 3))
|
2022-07-16 12:50:13 +08:00
|
|
|
assert.NoError(t, f.RemoveCol(sheetName, "H"))
|
|
|
|
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestAdjustTable.xlsx")))
|
|
|
|
|
|
|
|
f = NewFile()
|
2023-03-25 13:30:13 +08:00
|
|
|
assert.NoError(t, f.AddTable(sheetName, &Table{Range: "A1:D5"}))
|
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
|
|
|
// Test adjust table with non-table part
|
2022-07-16 12:50:13 +08:00
|
|
|
f.Pkg.Delete("xl/tables/table1.xml")
|
|
|
|
assert.NoError(t, f.RemoveRow(sheetName, 1))
|
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
|
|
|
// Test adjust table with unsupported charset
|
2022-07-16 12:50:13 +08:00
|
|
|
f.Pkg.Store("xl/tables/table1.xml", MacintoshCyrillicCharset)
|
|
|
|
assert.NoError(t, f.RemoveRow(sheetName, 1))
|
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
|
|
|
// Test adjust table with invalid table range reference
|
2022-07-16 12:50:13 +08:00
|
|
|
f.Pkg.Store("xl/tables/table1.xml", []byte(`<table ref="-" />`))
|
|
|
|
assert.NoError(t, f.RemoveRow(sheetName, 1))
|
|
|
|
}
|
|
|
|
|
2019-03-24 13:08:32 +08:00
|
|
|
func TestAdjustHelper(t *testing.T) {
|
|
|
|
f := NewFile()
|
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
|
|
|
_, err := f.NewSheet("Sheet2")
|
|
|
|
assert.NoError(t, err)
|
2021-07-05 00:03:56 +08:00
|
|
|
f.Sheet.Store("xl/worksheets/sheet1.xml", &xlsxWorksheet{
|
2022-01-23 00:32:34 +08:00
|
|
|
MergeCells: &xlsxMergeCells{Cells: []*xlsxMergeCell{{Ref: "A:B1"}}},
|
|
|
|
})
|
2021-07-05 00:03:56 +08:00
|
|
|
f.Sheet.Store("xl/worksheets/sheet2.xml", &xlsxWorksheet{
|
2022-01-23 00:32:34 +08:00
|
|
|
AutoFilter: &xlsxAutoFilter{Ref: "A1:B"},
|
|
|
|
})
|
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
|
|
|
// Test adjustHelper with illegal cell reference
|
2023-03-25 13:30:13 +08:00
|
|
|
assert.Equal(t, f.adjustHelper("Sheet1", rows, 0, 0), newCellNameToCoordinatesError("A", newInvalidCellNameError("A")))
|
|
|
|
assert.Equal(t, f.adjustHelper("Sheet2", rows, 0, 0), newCellNameToCoordinatesError("B", newInvalidCellNameError("B")))
|
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
|
|
|
// Test adjustHelper on not exists worksheet
|
2022-08-28 00:16:41 +08:00
|
|
|
assert.EqualError(t, f.adjustHelper("SheetN", rows, 0, 0), "sheet SheetN does not exist")
|
2019-03-24 13:08:32 +08:00
|
|
|
}
|
2019-06-08 00:00:55 +08:00
|
|
|
|
|
|
|
func TestAdjustCalcChain(t *testing.T) {
|
|
|
|
f := NewFile()
|
|
|
|
f.CalcChain = &xlsxCalcChain{
|
|
|
|
C: []xlsxCalcChainC{
|
2021-02-02 22:23:16 +08:00
|
|
|
{R: "B2", I: 2}, {R: "B2", I: 1},
|
2019-06-08 00:00:55 +08:00
|
|
|
},
|
|
|
|
}
|
2022-08-31 00:02:48 +08:00
|
|
|
assert.NoError(t, f.InsertCols("Sheet1", "A", 1))
|
|
|
|
assert.NoError(t, f.InsertRows("Sheet1", 1, 1))
|
2019-06-08 00:00:55 +08:00
|
|
|
|
2021-02-02 22:23:16 +08:00
|
|
|
f.CalcChain.C[1].R = "invalid coordinates"
|
2023-03-25 13:30:13 +08:00
|
|
|
assert.Equal(t, f.InsertCols("Sheet1", "A", 1), newCellNameToCoordinatesError("invalid coordinates", newInvalidCellNameError("invalid coordinates")))
|
2019-06-08 00:00:55 +08:00
|
|
|
f.CalcChain = nil
|
2022-08-31 00:02:48 +08:00
|
|
|
assert.NoError(t, f.InsertCols("Sheet1", "A", 1))
|
2019-06-08 00:00:55 +08:00
|
|
|
}
|
2022-11-11 01:50:07 +08:00
|
|
|
|
|
|
|
func TestAdjustCols(t *testing.T) {
|
|
|
|
sheetName := "Sheet1"
|
|
|
|
preset := func() (*File, error) {
|
|
|
|
f := NewFile()
|
|
|
|
if err := f.SetColWidth(sheetName, "J", "T", 5); err != nil {
|
|
|
|
return f, err
|
|
|
|
}
|
|
|
|
if err := f.SetSheetRow(sheetName, "J1", &[]string{"J1", "K1", "L1", "M1", "N1", "O1", "P1", "Q1", "R1", "S1", "T1"}); err != nil {
|
|
|
|
return f, err
|
|
|
|
}
|
|
|
|
return f, nil
|
|
|
|
}
|
|
|
|
baseTbl := []string{"B", "J", "O", "O", "O", "U", "V"}
|
|
|
|
insertTbl := []int{2, 2, 2, 5, 6, 2, 2}
|
|
|
|
expectedTbl := []map[string]float64{
|
|
|
|
{"J": defaultColWidth, "K": defaultColWidth, "U": 5, "V": 5, "W": defaultColWidth},
|
|
|
|
{"J": defaultColWidth, "K": defaultColWidth, "U": 5, "V": 5, "W": defaultColWidth},
|
|
|
|
{"O": 5, "P": 5, "U": 5, "V": 5, "W": defaultColWidth},
|
|
|
|
{"O": 5, "S": 5, "X": 5, "Y": 5, "Z": defaultColWidth},
|
|
|
|
{"O": 5, "S": 5, "Y": 5, "X": 5, "AA": defaultColWidth},
|
|
|
|
{"U": 5, "V": 5, "W": defaultColWidth},
|
|
|
|
{"U": defaultColWidth, "V": defaultColWidth, "W": defaultColWidth},
|
|
|
|
}
|
|
|
|
for idx, columnName := range baseTbl {
|
|
|
|
f, err := preset()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NoError(t, f.InsertCols(sheetName, columnName, insertTbl[idx]))
|
|
|
|
for column, expected := range expectedTbl[idx] {
|
|
|
|
width, err := f.GetColWidth(sheetName, column)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expected, width, column)
|
|
|
|
}
|
|
|
|
assert.NoError(t, f.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
baseTbl = []string{"B", "J", "O", "T"}
|
|
|
|
expectedTbl = []map[string]float64{
|
|
|
|
{"H": defaultColWidth, "I": 5, "S": 5, "T": defaultColWidth},
|
|
|
|
{"I": defaultColWidth, "J": 5, "S": 5, "T": defaultColWidth},
|
|
|
|
{"I": defaultColWidth, "O": 5, "S": 5, "T": defaultColWidth},
|
|
|
|
{"R": 5, "S": 5, "T": defaultColWidth, "U": defaultColWidth},
|
|
|
|
}
|
|
|
|
for idx, columnName := range baseTbl {
|
|
|
|
f, err := preset()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NoError(t, f.RemoveCol(sheetName, columnName))
|
|
|
|
for column, expected := range expectedTbl[idx] {
|
|
|
|
width, err := f.GetColWidth(sheetName, column)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expected, width, column)
|
|
|
|
}
|
|
|
|
assert.NoError(t, f.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
f, err := preset()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NoError(t, f.SetColWidth(sheetName, "I", "I", 8))
|
|
|
|
for i := 0; i <= 12; i++ {
|
|
|
|
assert.NoError(t, f.RemoveCol(sheetName, "I"))
|
|
|
|
}
|
|
|
|
for c := 9; c <= 21; c++ {
|
|
|
|
columnName, err := ColumnNumberToName(c)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
width, err := f.GetColWidth(sheetName, columnName)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, defaultColWidth, width, columnName)
|
|
|
|
}
|
|
|
|
|
|
|
|
ws, ok := f.Sheet.Load("xl/worksheets/sheet1.xml")
|
|
|
|
assert.True(t, ok)
|
|
|
|
ws.(*xlsxWorksheet).Cols = nil
|
|
|
|
assert.NoError(t, f.RemoveCol(sheetName, "A"))
|
|
|
|
|
|
|
|
assert.NoError(t, f.Close())
|
|
|
|
}
|
2023-07-04 00:06:37 +08:00
|
|
|
|
|
|
|
func TestAdjustFormula(t *testing.T) {
|
|
|
|
f := NewFile()
|
|
|
|
formulaType, ref := STCellFormulaTypeShared, "C1:C5"
|
|
|
|
assert.NoError(t, f.SetCellFormula("Sheet1", "C1", "=A1+B1", FormulaOpts{Ref: &ref, Type: &formulaType}))
|
|
|
|
assert.NoError(t, f.DuplicateRowTo("Sheet1", 1, 10))
|
|
|
|
assert.NoError(t, f.InsertCols("Sheet1", "B", 1))
|
|
|
|
assert.NoError(t, f.InsertRows("Sheet1", 1, 1))
|
|
|
|
for cell, expected := range map[string]string{"D2": "=A1+B1", "D3": "=A2+B2", "D11": "=A1+B1"} {
|
|
|
|
formula, err := f.GetCellFormula("Sheet1", cell)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, expected, formula)
|
|
|
|
}
|
|
|
|
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestAdjustFormula.xlsx")))
|
|
|
|
assert.NoError(t, f.Close())
|
|
|
|
|
|
|
|
assert.NoError(t, f.adjustFormula(nil, rows, 0, false))
|
|
|
|
assert.Equal(t, f.adjustFormula(&xlsxF{Ref: "-"}, rows, 0, false), ErrParameterInvalid)
|
|
|
|
assert.Equal(t, f.adjustFormula(&xlsxF{Ref: "XFD1:XFD1"}, columns, 1, false), ErrColumnNumber)
|
|
|
|
}
|