Skip to content

Commit

Permalink
New function DeleteSlicer (#30)
Browse files Browse the repository at this point in the history
- Update the unit tests and documentation
  • Loading branch information
centurion-hub authored Sep 28, 2024
1 parent 63cc7c2 commit 7ee4da1
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 15 deletions.
10 changes: 5 additions & 5 deletions cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/stretchr/testify v1.8.4
github.com/xuri/excelize/v2 v2.8.2-0.20240817161802-9a386575152d
github.com/xuri/excelize/v2 v2.8.2-0.20240927065818-bebb8020699e
golang.org/x/image v0.19.0
)

Expand All @@ -13,11 +13,11 @@ require (
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/richardlehane/mscfb v1.0.4 // indirect
github.com/richardlehane/msoleps v1.0.3 // indirect
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.26.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/text v0.17.0 // 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
gopkg.in/yaml.v3 v3.0.1 // indirect
)
20 changes: 10 additions & 10 deletions cmd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/richardlehane/mscfb v1.0.4 h1:WULscsljNPConisD5hR0+OyZjwK46Pfyr6mPu5ZawpM=
github.com/richardlehane/mscfb v1.0.4/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk=
github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
github.com/richardlehane/msoleps v1.0.3 h1:aznSZzrwYRl3rLKRT3gUk9am7T/mLNSnJINvN0AQoVM=
github.com/richardlehane/msoleps v1.0.3/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
github.com/richardlehane/msoleps v1.0.4 h1:WuESlvhX3gH2IHcd8UqyCuFY5yiq/GR/yqaSM/9/g00=
github.com/richardlehane/msoleps v1.0.4/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d h1:llb0neMWDQe87IzJLS4Ci7psK/lVsjIS2otl+1WyRyY=
github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
github.com/xuri/excelize/v2 v2.8.2-0.20240817161802-9a386575152d h1:jdlS3YAi4lfGkLTVLOfBkmIMSTewPugizWstqPa9/Zc=
github.com/xuri/excelize/v2 v2.8.2-0.20240817161802-9a386575152d/go.mod h1:0hWeRQBdU+HQng3S1AXdYm8Ob0dbevUncXAWI0QswPU=
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/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.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
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/image v0.19.0 h1:D9FX4QWkLfkeqaC62SonffIIuYdOk/UE2XKUBgRIBIQ=
golang.org/x/image v0.19.0/go.mod h1:y0zrRqlQRWQ5PXaYCOMLTW2fpsxZ8Qh9I/ohnInJEys=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
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/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.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
18 changes: 18 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ func regInteropFunc(f *excelize.File, fn map[string]interface{}) interface{} {
"DeleteFormControl": DeleteFormControl(f),
"DeletePicture": DeletePicture(f),
"DeleteSheet": DeleteSheet(f),
"DeleteSlicer": DeleteSlicer(f),
"DeleteTable": DeleteTable(f),
"DuplicateRow": DuplicateRow(f),
"DuplicateRowTo": DuplicateRowTo(f),
Expand Down Expand Up @@ -1541,6 +1542,23 @@ func DeleteSheet(f *excelize.File) func(this js.Value, args []js.Value) interfac
}
}

// DeleteSlicer provides the method to delete a slicer by a given slicer name.
func DeleteSlicer(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}
if err := prepareArgs(args, []argsRule{
{types: []js.Type{js.TypeString}},
}); err != nil {
ret["error"] = err.Error()
return js.ValueOf(ret)
}
if err := f.DeleteSlicer(args[0].String()); err != nil {
ret["error"] = err.Error()
}
return js.ValueOf(ret)
}
}

// DeleteTable provides the method to delete table by given table name.
func DeleteTable(f *excelize.File) func(this js.Value, args []js.Value) interface{} {
return func(this js.Value, args []js.Value) interface{} {
Expand Down
12 changes: 12 additions & 0 deletions cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,9 @@ func TestSlicer(t *testing.T) {
}))
assert.True(t, ret.Get("error").IsNull())

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

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

Expand All @@ -694,6 +697,15 @@ func TestSlicer(t *testing.T) {
"Caption": "Column1",
}))
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
7 changes: 7 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1998,6 +1998,13 @@ declare module 'excelize-wasm' {
*/
DeleteSheet(sheet: string): { error: string | null }

/**
* DeleteSlicer provides the method to delete a slicer by a given slicer
* name.
* @param name The slicer name
*/
DeleteSlicer(name: string): { error: string | null }

/**
* DeleteTable provides the method to delete table by given table name.
* @param name The table name
Expand Down

0 comments on commit 7ee4da1

Please sign in to comment.