Skip to content

Commit ef25ac8

Browse files
committed
New function GetSlicers has been added
- Add new CultureNameJaJP, CultureNameKoKR and CultureNameZhTW enumeration values - Add new fields ShowAll, InsertBlankRow and NumFmt field in the PivotTableField data type - Add new fields ClassicLayout, FieldPrintTitles and ItemPrintTitles in the PivotTableOptions data type - Introduce new exported ChartLineUnset enumeration value - Update GitHub Action configurations build with Go 1.23.x - Upgrade the JavaScript bundler version and the Excelize library version
1 parent 7ee4da1 commit ef25ac8

File tree

9 files changed

+472
-460
lines changed

9 files changed

+472
-460
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
test:
1111
strategy:
1212
matrix:
13-
go-version: [1.22.x]
13+
go-version: [1.23.x]
1414
os: [ubuntu-latest]
1515
targetplatform: [x64]
1616

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
publish:
99
strategy:
1010
matrix:
11-
go-version: [1.22.x]
11+
go-version: [1.23.x]
1212
os: [ubuntu-latest]
1313
targetplatform: [x64]
1414

cmd/go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ go 1.18
44

55
require (
66
github.com/stretchr/testify v1.8.4
7-
github.com/xuri/excelize/v2 v2.8.2-0.20240927065818-bebb8020699e
8-
golang.org/x/image v0.19.0
7+
github.com/xuri/excelize/v2 v2.9.1-0.20241021013604-d1937a0cde23
8+
golang.org/x/image v0.21.0
99
)
1010

1111
require (
@@ -16,8 +16,8 @@ require (
1616
github.com/richardlehane/msoleps v1.0.4 // indirect
1717
github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d // indirect
1818
github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7 // indirect
19-
golang.org/x/crypto v0.27.0 // indirect
20-
golang.org/x/net v0.29.0 // indirect
21-
golang.org/x/text v0.18.0 // indirect
19+
golang.org/x/crypto v0.28.0 // indirect
20+
golang.org/x/net v0.30.0 // indirect
21+
golang.org/x/text v0.19.0 // indirect
2222
gopkg.in/yaml.v3 v3.0.1 // indirect
2323
)

cmd/go.sum

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,28 @@ github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d h1:llb0neMWDQe87IzJLS4Ci7
1515
github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
1616
github.com/xuri/excelize/v2 v2.8.2-0.20240927065818-bebb8020699e h1:7/Og1+RKX9BMPuOfR+VjRha6Bz4au5vTxnuFpR0uv6M=
1717
github.com/xuri/excelize/v2 v2.8.2-0.20240927065818-bebb8020699e/go.mod h1:NlXCtlzkDyT7TF4yZvEKmoWx5eLmtJiJjPgJMtxKnv8=
18+
github.com/xuri/excelize/v2 v2.9.0 h1:1tgOaEq92IOEumR1/JfYS/eR0KHOCsRv/rYXXh6YJQE=
19+
github.com/xuri/excelize/v2 v2.9.0/go.mod h1:uqey4QBZ9gdMeWApPLdhm9x+9o2lq4iVmjiLfBS5hdE=
20+
github.com/xuri/excelize/v2 v2.9.1-0.20241021013604-d1937a0cde23 h1:+p06nEmhW37XGxhLvSWofLt1G9w+z2AbdHLz04ovbdU=
21+
github.com/xuri/excelize/v2 v2.9.1-0.20241021013604-d1937a0cde23/go.mod h1:uqey4QBZ9gdMeWApPLdhm9x+9o2lq4iVmjiLfBS5hdE=
1822
github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7 h1:hPVCafDV85blFTabnqKgNhDCkJX25eik94Si9cTER4A=
1923
github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
2024
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
2125
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
26+
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
27+
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
2228
golang.org/x/image v0.19.0 h1:D9FX4QWkLfkeqaC62SonffIIuYdOk/UE2XKUBgRIBIQ=
2329
golang.org/x/image v0.19.0/go.mod h1:y0zrRqlQRWQ5PXaYCOMLTW2fpsxZ8Qh9I/ohnInJEys=
30+
golang.org/x/image v0.21.0 h1:c5qV36ajHpdj4Qi0GnE0jUc/yuo33OLFaa0d+crTD5s=
31+
golang.org/x/image v0.21.0/go.mod h1:vUbsLavqK/W303ZroQQVKQ+Af3Yl6Uz1Ppu5J/cLz78=
2432
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
2533
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
34+
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
35+
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
2636
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
2737
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
38+
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
39+
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
2840
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2941
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
3042
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

cmd/main.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,10 @@ func regConstants() {
193193
// CultureName enumeration
194194
"CultureNameUnknown": int(excelize.CultureNameUnknown),
195195
"CultureNameEnUS": int(excelize.CultureNameEnUS),
196+
"CultureNameJaJP": int(excelize.CultureNameJaJP),
197+
"CultureNameKoKR": int(excelize.CultureNameKoKR),
196198
"CultureNameZhCN": int(excelize.CultureNameZhCN),
199+
"CultureNameZhTW": int(excelize.CultureNameZhTW),
197200
// FormControlType enumeration
198201
"FormControlNote": int(excelize.FormControlNote),
199202
"FormControlButton": int(excelize.FormControlButton),
@@ -260,6 +263,7 @@ func regConstants() {
260263
"Bubble": int(excelize.Bubble),
261264
"Bubble3D": int(excelize.Bubble3D),
262265
// ChartLineType enumeration
266+
"ChartLineUnset": int(excelize.ChartLineUnset),
263267
"ChartLineSolid": int(excelize.ChartLineSolid),
264268
"ChartLineNone": int(excelize.ChartLineNone),
265269
"ChartLineAutomatic": int(excelize.ChartLineAutomatic),
@@ -354,6 +358,7 @@ func regInteropFunc(f *excelize.File, fn map[string]interface{}) interface{} {
354358
"GetSheetProps": GetSheetProps(f),
355359
"GetSheetView": GetSheetView(f),
356360
"GetSheetVisible": GetSheetVisible(f),
361+
"GetSlicers": GetSlicers(f),
357362
"GetStyle": GetStyle(f),
358363
"GetTables": GetTables(f),
359364
"GetWorkbookProps": GetWorkbookProps(f),
@@ -2525,6 +2530,35 @@ func GetSheetVisible(f *excelize.File) func(this js.Value, args []js.Value) inte
25252530
}
25262531
}
25272532

2533+
// GetSlicers provides the method to get all slicers in a worksheet by a given
2534+
// worksheet name. Note that, this function does not support getting the height,
2535+
// width, and graphic options of the slicer shape currently.
2536+
func GetSlicers(f *excelize.File) func(this js.Value, args []js.Value) interface{} {
2537+
return func(this js.Value, args []js.Value) interface{} {
2538+
ret := map[string]interface{}{"slicers": []interface{}{}, "error": nil}
2539+
if err := prepareArgs(args, []argsRule{
2540+
{types: []js.Type{js.TypeString}},
2541+
}); err != nil {
2542+
ret["error"] = err.Error()
2543+
return js.ValueOf(ret)
2544+
}
2545+
slicers, err := f.GetSlicers(args[0].String())
2546+
if err != nil {
2547+
ret["error"] = err.Error()
2548+
return js.ValueOf(ret)
2549+
}
2550+
for _, slicer := range slicers {
2551+
if jsVal, err := goValueToJS(reflect.ValueOf(slicer),
2552+
reflect.TypeOf(excelize.SlicerOptions{})); err == nil {
2553+
x := ret["slicers"].([]interface{})
2554+
x = append(x, jsVal)
2555+
ret["slicers"] = x
2556+
}
2557+
}
2558+
return js.ValueOf(ret)
2559+
}
2560+
}
2561+
25282562
// GetStyle provides a function to get style definition by given style index.
25292563
func GetStyle(f *excelize.File) func(this js.Value, args []js.Value) interface{} {
25302564
return func(this js.Value, args []js.Value) interface{} {

cmd/main_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,11 @@ func TestSlicer(t *testing.T) {
675675
}))
676676
assert.True(t, ret.Get("error").IsNull())
677677

678+
ret = f.(js.Value).Call("GetSlicers", js.ValueOf("Sheet1"))
679+
assert.True(t, ret.Get("error").IsNull())
680+
assert.Equal(t, 1, ret.Get("slicers").Length())
681+
assert.Equal(t, "Column1", ret.Get("slicers").Index(0).Get("Name").String())
682+
678683
ret = f.(js.Value).Call("DeleteSlicer", js.ValueOf("Column1"))
679684
assert.True(t, ret.Get("error").IsNull())
680685

@@ -706,6 +711,24 @@ func TestSlicer(t *testing.T) {
706711

707712
ret = f.(js.Value).Call("DeleteSlicer", js.ValueOf(nil))
708713
assert.EqualError(t, errArgType, ret.Get("error").String())
714+
715+
ret = f.(js.Value).Call("GetSlicers")
716+
assert.EqualError(t, errArgNum, ret.Get("error").String())
717+
718+
ret = f.(js.Value).Call("GetSlicers", js.ValueOf(nil))
719+
assert.EqualError(t, errArgType, ret.Get("error").String())
720+
721+
ret = f.(js.Value).Call("GetSlicers", js.ValueOf("SheetN"))
722+
assert.Equal(t, "sheet SheetN does not exist", ret.Get("error").String())
723+
724+
ret = f.(js.Value).Call("DeleteSlicer", js.ValueOf("X"))
725+
assert.Equal(t, "slicer X does not exist", ret.Get("error").String())
726+
727+
ret = f.(js.Value).Call("DeleteSlicer")
728+
assert.EqualError(t, errArgNum, ret.Get("error").String())
729+
730+
ret = f.(js.Value).Call("DeleteSlicer", js.ValueOf(nil))
731+
assert.EqualError(t, errArgType, ret.Get("error").String())
709732
}
710733

711734
func TestAddSparkline(t *testing.T) {

0 commit comments

Comments
 (0)