Skip to content

Commit

Permalink
New function GetSlicers has been added
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
xuri committed Oct 22, 2024
1 parent 7ee4da1 commit ef25ac8
Show file tree
Hide file tree
Showing 9 changed files with 472 additions and 460 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.22.x]
go-version: [1.23.x]
os: [ubuntu-latest]
targetplatform: [x64]

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
publish:
strategy:
matrix:
go-version: [1.22.x]
go-version: [1.23.x]
os: [ubuntu-latest]
targetplatform: [x64]

Expand Down
10 changes: 5 additions & 5 deletions cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.18

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

require (
Expand All @@ -16,8 +16,8 @@ require (
github.com/richardlehane/msoleps v1.0.4 // indirect
github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d // indirect
github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/text v0.19.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
12 changes: 12 additions & 0 deletions cmd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,28 @@ github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d h1:llb0neMWDQe87IzJLS4Ci7
github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
github.com/xuri/excelize/v2 v2.8.2-0.20240927065818-bebb8020699e h1:7/Og1+RKX9BMPuOfR+VjRha6Bz4au5vTxnuFpR0uv6M=
github.com/xuri/excelize/v2 v2.8.2-0.20240927065818-bebb8020699e/go.mod h1:NlXCtlzkDyT7TF4yZvEKmoWx5eLmtJiJjPgJMtxKnv8=
github.com/xuri/excelize/v2 v2.9.0 h1:1tgOaEq92IOEumR1/JfYS/eR0KHOCsRv/rYXXh6YJQE=
github.com/xuri/excelize/v2 v2.9.0/go.mod h1:uqey4QBZ9gdMeWApPLdhm9x+9o2lq4iVmjiLfBS5hdE=
github.com/xuri/excelize/v2 v2.9.1-0.20241021013604-d1937a0cde23 h1:+p06nEmhW37XGxhLvSWofLt1G9w+z2AbdHLz04ovbdU=
github.com/xuri/excelize/v2 v2.9.1-0.20241021013604-d1937a0cde23/go.mod h1:uqey4QBZ9gdMeWApPLdhm9x+9o2lq4iVmjiLfBS5hdE=
github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7 h1:hPVCafDV85blFTabnqKgNhDCkJX25eik94Si9cTER4A=
github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/image v0.19.0 h1:D9FX4QWkLfkeqaC62SonffIIuYdOk/UE2XKUBgRIBIQ=
golang.org/x/image v0.19.0/go.mod h1:y0zrRqlQRWQ5PXaYCOMLTW2fpsxZ8Qh9I/ohnInJEys=
golang.org/x/image v0.21.0 h1:c5qV36ajHpdj4Qi0GnE0jUc/yuo33OLFaa0d+crTD5s=
golang.org/x/image v0.21.0/go.mod h1:vUbsLavqK/W303ZroQQVKQ+Af3Yl6Uz1Ppu5J/cLz78=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
34 changes: 34 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ func regConstants() {
// CultureName enumeration
"CultureNameUnknown": int(excelize.CultureNameUnknown),
"CultureNameEnUS": int(excelize.CultureNameEnUS),
"CultureNameJaJP": int(excelize.CultureNameJaJP),
"CultureNameKoKR": int(excelize.CultureNameKoKR),
"CultureNameZhCN": int(excelize.CultureNameZhCN),
"CultureNameZhTW": int(excelize.CultureNameZhTW),
// FormControlType enumeration
"FormControlNote": int(excelize.FormControlNote),
"FormControlButton": int(excelize.FormControlButton),
Expand Down Expand Up @@ -260,6 +263,7 @@ func regConstants() {
"Bubble": int(excelize.Bubble),
"Bubble3D": int(excelize.Bubble3D),
// ChartLineType enumeration
"ChartLineUnset": int(excelize.ChartLineUnset),
"ChartLineSolid": int(excelize.ChartLineSolid),
"ChartLineNone": int(excelize.ChartLineNone),
"ChartLineAutomatic": int(excelize.ChartLineAutomatic),
Expand Down Expand Up @@ -354,6 +358,7 @@ func regInteropFunc(f *excelize.File, fn map[string]interface{}) interface{} {
"GetSheetProps": GetSheetProps(f),
"GetSheetView": GetSheetView(f),
"GetSheetVisible": GetSheetVisible(f),
"GetSlicers": GetSlicers(f),
"GetStyle": GetStyle(f),
"GetTables": GetTables(f),
"GetWorkbookProps": GetWorkbookProps(f),
Expand Down Expand Up @@ -2525,6 +2530,35 @@ func GetSheetVisible(f *excelize.File) func(this js.Value, args []js.Value) inte
}
}

// GetSlicers provides the method to get all slicers in a worksheet by a given
// worksheet name. Note that, this function does not support getting the height,
// width, and graphic options of the slicer shape currently.
func GetSlicers(f *excelize.File) func(this js.Value, args []js.Value) interface{} {
return func(this js.Value, args []js.Value) interface{} {
ret := map[string]interface{}{"slicers": []interface{}{}, "error": nil}
if err := prepareArgs(args, []argsRule{
{types: []js.Type{js.TypeString}},
}); err != nil {
ret["error"] = err.Error()
return js.ValueOf(ret)
}
slicers, err := f.GetSlicers(args[0].String())
if err != nil {
ret["error"] = err.Error()
return js.ValueOf(ret)
}
for _, slicer := range slicers {
if jsVal, err := goValueToJS(reflect.ValueOf(slicer),
reflect.TypeOf(excelize.SlicerOptions{})); err == nil {
x := ret["slicers"].([]interface{})
x = append(x, jsVal)
ret["slicers"] = x
}
}
return js.ValueOf(ret)
}
}

// GetStyle provides a function to get style definition by given style index.
func GetStyle(f *excelize.File) func(this js.Value, args []js.Value) interface{} {
return func(this js.Value, args []js.Value) interface{} {
Expand Down
23 changes: 23 additions & 0 deletions cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,11 @@ func TestSlicer(t *testing.T) {
}))
assert.True(t, ret.Get("error").IsNull())

ret = f.(js.Value).Call("GetSlicers", js.ValueOf("Sheet1"))
assert.True(t, ret.Get("error").IsNull())
assert.Equal(t, 1, ret.Get("slicers").Length())
assert.Equal(t, "Column1", ret.Get("slicers").Index(0).Get("Name").String())

ret = f.(js.Value).Call("DeleteSlicer", js.ValueOf("Column1"))
assert.True(t, ret.Get("error").IsNull())

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

ret = f.(js.Value).Call("DeleteSlicer", js.ValueOf(nil))
assert.EqualError(t, errArgType, ret.Get("error").String())

ret = f.(js.Value).Call("GetSlicers")
assert.EqualError(t, errArgNum, ret.Get("error").String())

ret = f.(js.Value).Call("GetSlicers", js.ValueOf(nil))
assert.EqualError(t, errArgType, ret.Get("error").String())

ret = f.(js.Value).Call("GetSlicers", js.ValueOf("SheetN"))
assert.Equal(t, "sheet SheetN does not exist", ret.Get("error").String())

ret = f.(js.Value).Call("DeleteSlicer", js.ValueOf("X"))
assert.Equal(t, "slicer X does not exist", ret.Get("error").String())

ret = f.(js.Value).Call("DeleteSlicer")
assert.EqualError(t, errArgNum, ret.Get("error").String())

ret = f.(js.Value).Call("DeleteSlicer", js.ValueOf(nil))
assert.EqualError(t, errArgType, ret.Get("error").String())
}

func TestAddSparkline(t *testing.T) {
Expand Down
Loading

0 comments on commit ef25ac8

Please sign in to comment.