Skip to content

Commit

Permalink
The AddSlicer function now support create pivot table slicer
Browse files Browse the repository at this point in the history
- Upgrade the Excelize to the master branch code
  • Loading branch information
xuri committed Sep 28, 2023
1 parent 32fee8d commit 15c4561
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.16

require (
github.com/stretchr/testify v1.8.1
github.com/xuri/excelize/v2 v2.8.1-0.20230920160631-9c079e5eec19
github.com/xuri/excelize/v2 v2.8.1-0.20230928005354-1c23dc3507c6
github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 // indirect
golang.org/x/image v0.12.0
)
4 changes: 2 additions & 2 deletions cmd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/xuri/efp v0.0.0-20230802181842-ad255f2331ca h1:uvPMDVyP7PXMMioYdyPH+0O+Ta/UO1WFfNYMO3Wz0eg=
github.com/xuri/efp v0.0.0-20230802181842-ad255f2331ca/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
github.com/xuri/excelize/v2 v2.8.1-0.20230920160631-9c079e5eec19 h1:+Ytc0a/vdT7PohdI9nvn8IjTLm6dtnDoWyJeA8xnGno=
github.com/xuri/excelize/v2 v2.8.1-0.20230920160631-9c079e5eec19/go.mod h1:GKocsEKQZgdn03padVqGDQpXV9NX2tNf1bqc9cFk7nE=
github.com/xuri/excelize/v2 v2.8.1-0.20230928005354-1c23dc3507c6 h1:xUVR0duWw+DpXY1tNvQMw/0C7Cb5IetLZpzULoRfWIk=
github.com/xuri/excelize/v2 v2.8.1-0.20230928005354-1c23dc3507c6/go.mod h1:GKocsEKQZgdn03padVqGDQpXV9NX2tNf1bqc9cFk7nE=
github.com/xuri/nfp v0.0.0-20230918160701-e5a3f5b24785/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 h1:qhbILQo1K3mphbwKh1vNm4oGezE1eF9fQWmNiIpSfI4=
github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ func AddShape(f *excelize.File) func(this js.Value, args []js.Value) interface{}
}

// AddSlicer function inserts a slicer by giving the worksheet name and slicer
// settings. The pivot table slicer is not supported currently.
// settings.
func AddSlicer(f *excelize.File) func(this js.Value, args []js.Value) interface{} {
return func(this js.Value, args []js.Value) interface{} {
ret := map[string]interface{}{"error": nil}
Expand Down
19 changes: 16 additions & 3 deletions cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,18 @@ func TestSlicer(t *testing.T) {
f := NewFile(js.Value{}, []js.Value{})
assert.True(t, f.(js.Value).Get("error").IsNull())

ret := f.(js.Value).Call("AddTable", js.ValueOf("Sheet1"), js.ValueOf(map[string]interface{}{"Name": "Table1", "Range": "A1:D5"}))
ret := f.(js.Value).Call("AddTable", js.ValueOf("Sheet1"),
js.ValueOf(map[string]interface{}{"Name": "Table1", "Range": "A1:D5"}))
assert.True(t, ret.Get("error").IsNull())

ret = f.(js.Value).Call("AddSlicer", js.ValueOf("Sheet1"),
js.ValueOf(map[string]interface{}{"Name": "Column1", "Table": "Table1", "Cell": "E1", "Caption": "Column1"}))
js.ValueOf(map[string]interface{}{
"Name": "Column1",
"Cell": "E1",
"TableSheet": "Sheet1",
"TableName": "Table1",
"Caption": "Column1",
}))
assert.True(t, ret.Get("error").IsNull())

ret = f.(js.Value).Call("AddSlicer")
Expand All @@ -663,7 +670,13 @@ func TestSlicer(t *testing.T) {
assert.EqualError(t, errArgType, ret.Get("error").String())

ret = f.(js.Value).Call("AddSlicer", js.ValueOf("SheetN"),
js.ValueOf(map[string]interface{}{"Name": "Table1", "Table": "Column1", "Cell": "E1", "Caption": "Column1"}))
js.ValueOf(map[string]interface{}{
"Name": "Column1",
"Cell": "E1",
"TableSheet": "SheetN",
"TableName": "Table1",
"Caption": "Column1",
}))
assert.Equal(t, "sheet SheetN does not exist", ret.Get("error").String())
}

Expand Down
14 changes: 9 additions & 5 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,15 @@ declare module 'excelize-wasm' {
* Name specifies the slicer name, should be an existing field name of the
* given table or pivot table, this setting is required.
*
* Table specifies the name of the table or pivot table, this setting is
* required.
*
* Cell specifies the left top cell coordinates the position for inserting the
* slicer, this setting is required.
*
* TableSheet specifies the worksheet name of the table or pivot table, this
* setting is required.
*
* TableName specifies the name of the table or pivot table, this setting is
* required.
*
* Caption specifies the caption of the slicer, this setting is optional.
*
* Macro used for set macro for the slicer, the workbook extension should be
Expand All @@ -269,8 +272,9 @@ declare module 'excelize-wasm' {
*/
export type SlicerOptions = {
Name: string;
Table: string;
Cell: string;
TableSheet: string;
TableName: string;
Caption?: string;
Macro?: string;
Width?: number;
Expand Down Expand Up @@ -1162,7 +1166,7 @@ declare module 'excelize-wasm' {

/**
* AddSlicer function inserts a slicer by giving the worksheet name and
* slicer settings. The pivot table slicer is not supported currently.
* slicer settings.
* @param sheet The worksheet name
* @param opts The slicer options
*/
Expand Down

0 comments on commit 15c4561

Please sign in to comment.