Skip to content

Commit 7ee4da1

Browse files
New function DeleteSlicer (#30)
- Update the unit tests and documentation
1 parent 63cc7c2 commit 7ee4da1

File tree

5 files changed

+52
-15
lines changed

5 files changed

+52
-15
lines changed

cmd/go.mod

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

55
require (
66
github.com/stretchr/testify v1.8.4
7-
github.com/xuri/excelize/v2 v2.8.2-0.20240817161802-9a386575152d
7+
github.com/xuri/excelize/v2 v2.8.2-0.20240927065818-bebb8020699e
88
golang.org/x/image v0.19.0
99
)
1010

@@ -13,11 +13,11 @@ require (
1313
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
1414
github.com/pmezard/go-difflib v1.0.0 // indirect
1515
github.com/richardlehane/mscfb v1.0.4 // indirect
16-
github.com/richardlehane/msoleps v1.0.3 // indirect
16+
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.26.0 // indirect
20-
golang.org/x/net v0.28.0 // indirect
21-
golang.org/x/text v0.17.0 // 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
2222
gopkg.in/yaml.v3 v3.0.1 // indirect
2323
)

cmd/go.sum

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
77
github.com/richardlehane/mscfb v1.0.4 h1:WULscsljNPConisD5hR0+OyZjwK46Pfyr6mPu5ZawpM=
88
github.com/richardlehane/mscfb v1.0.4/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk=
99
github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
10-
github.com/richardlehane/msoleps v1.0.3 h1:aznSZzrwYRl3rLKRT3gUk9am7T/mLNSnJINvN0AQoVM=
11-
github.com/richardlehane/msoleps v1.0.3/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
10+
github.com/richardlehane/msoleps v1.0.4 h1:WuESlvhX3gH2IHcd8UqyCuFY5yiq/GR/yqaSM/9/g00=
11+
github.com/richardlehane/msoleps v1.0.4/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
1212
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
1313
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
1414
github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d h1:llb0neMWDQe87IzJLS4Ci7psK/lVsjIS2otl+1WyRyY=
1515
github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
16-
github.com/xuri/excelize/v2 v2.8.2-0.20240817161802-9a386575152d h1:jdlS3YAi4lfGkLTVLOfBkmIMSTewPugizWstqPa9/Zc=
17-
github.com/xuri/excelize/v2 v2.8.2-0.20240817161802-9a386575152d/go.mod h1:0hWeRQBdU+HQng3S1AXdYm8Ob0dbevUncXAWI0QswPU=
16+
github.com/xuri/excelize/v2 v2.8.2-0.20240927065818-bebb8020699e h1:7/Og1+RKX9BMPuOfR+VjRha6Bz4au5vTxnuFpR0uv6M=
17+
github.com/xuri/excelize/v2 v2.8.2-0.20240927065818-bebb8020699e/go.mod h1:NlXCtlzkDyT7TF4yZvEKmoWx5eLmtJiJjPgJMtxKnv8=
1818
github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7 h1:hPVCafDV85blFTabnqKgNhDCkJX25eik94Si9cTER4A=
1919
github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
20-
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
21-
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
20+
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
21+
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
2222
golang.org/x/image v0.19.0 h1:D9FX4QWkLfkeqaC62SonffIIuYdOk/UE2XKUBgRIBIQ=
2323
golang.org/x/image v0.19.0/go.mod h1:y0zrRqlQRWQ5PXaYCOMLTW2fpsxZ8Qh9I/ohnInJEys=
24-
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
25-
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
26-
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
27-
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
24+
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
25+
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
26+
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
27+
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
2828
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
2929
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
3030
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

cmd/main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ func regInteropFunc(f *excelize.File, fn map[string]interface{}) interface{} {
312312
"DeleteFormControl": DeleteFormControl(f),
313313
"DeletePicture": DeletePicture(f),
314314
"DeleteSheet": DeleteSheet(f),
315+
"DeleteSlicer": DeleteSlicer(f),
315316
"DeleteTable": DeleteTable(f),
316317
"DuplicateRow": DuplicateRow(f),
317318
"DuplicateRowTo": DuplicateRowTo(f),
@@ -1541,6 +1542,23 @@ func DeleteSheet(f *excelize.File) func(this js.Value, args []js.Value) interfac
15411542
}
15421543
}
15431544

1545+
// DeleteSlicer provides the method to delete a slicer by a given slicer name.
1546+
func DeleteSlicer(f *excelize.File) func(this js.Value, args []js.Value) interface{} {
1547+
return func(this js.Value, args []js.Value) interface{} {
1548+
ret := map[string]interface{}{"error": nil}
1549+
if err := prepareArgs(args, []argsRule{
1550+
{types: []js.Type{js.TypeString}},
1551+
}); err != nil {
1552+
ret["error"] = err.Error()
1553+
return js.ValueOf(ret)
1554+
}
1555+
if err := f.DeleteSlicer(args[0].String()); err != nil {
1556+
ret["error"] = err.Error()
1557+
}
1558+
return js.ValueOf(ret)
1559+
}
1560+
}
1561+
15441562
// DeleteTable provides the method to delete table by given table name.
15451563
func DeleteTable(f *excelize.File) func(this js.Value, args []js.Value) interface{} {
15461564
return func(this js.Value, args []js.Value) interface{} {

cmd/main_test.go

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

678+
ret = f.(js.Value).Call("DeleteSlicer", js.ValueOf("Column1"))
679+
assert.True(t, ret.Get("error").IsNull())
680+
678681
ret = f.(js.Value).Call("AddSlicer")
679682
assert.EqualError(t, errArgNum, ret.Get("error").String())
680683

@@ -694,6 +697,15 @@ func TestSlicer(t *testing.T) {
694697
"Caption": "Column1",
695698
}))
696699
assert.Equal(t, "sheet SheetN does not exist", ret.Get("error").String())
700+
701+
ret = f.(js.Value).Call("DeleteSlicer", js.ValueOf("X"))
702+
assert.Equal(t, "slicer X does not exist", ret.Get("error").String())
703+
704+
ret = f.(js.Value).Call("DeleteSlicer")
705+
assert.EqualError(t, errArgNum, ret.Get("error").String())
706+
707+
ret = f.(js.Value).Call("DeleteSlicer", js.ValueOf(nil))
708+
assert.EqualError(t, errArgType, ret.Get("error").String())
697709
}
698710

699711
func TestAddSparkline(t *testing.T) {

src/index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,6 +1998,13 @@ declare module 'excelize-wasm' {
19981998
*/
19991999
DeleteSheet(sheet: string): { error: string | null }
20002000

2001+
/**
2002+
* DeleteSlicer provides the method to delete a slicer by a given slicer
2003+
* name.
2004+
* @param name The slicer name
2005+
*/
2006+
DeleteSlicer(name: string): { error: string | null }
2007+
20012008
/**
20022009
* DeleteTable provides the method to delete table by given table name.
20032010
* @param name The table name

0 commit comments

Comments
 (0)