Skip to content

Commit

Permalink
New function GetPanes has been added
Browse files Browse the repository at this point in the history
  • Loading branch information
xuri committed Jun 11, 2023
1 parent ea176a4 commit e9ceb74
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 14 deletions.
5 changes: 2 additions & 3 deletions cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.16

require (
github.com/stretchr/testify v1.8.1
github.com/xuri/excelize/v2 v2.7.2-0.20230522161855-76cd0992b038
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/image v0.5.0
github.com/xuri/excelize/v2 v2.7.2-0.20230608015038-78c974d855e4
golang.org/x/image v0.7.0
)
11 changes: 4 additions & 7 deletions cmd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,24 @@ 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-20230422071738-01f4e37c47e9 h1:ge5g8vsTQclA5lXDi+PuiAFw5GMIlMHOB/5e1hsf96E=
github.com/xuri/efp v0.0.0-20230422071738-01f4e37c47e9/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
github.com/xuri/excelize/v2 v2.7.2-0.20230522161855-76cd0992b038 h1:u3RqvaH87/5qqGjMP5au7XPcxh2yEtRWm7RbMncM0is=
github.com/xuri/excelize/v2 v2.7.2-0.20230522161855-76cd0992b038/go.mod h1:ejxK/GVQckqRTIU0qzshtlPKdiWdxLtkjT6/x842Lzg=
github.com/xuri/excelize/v2 v2.7.2-0.20230608015038-78c974d855e4 h1:75hO6YIKiCbanYuOFlG9BBH0b7rT0+5VrfOCuHB5Bt0=
github.com/xuri/excelize/v2 v2.7.2-0.20230608015038-78c974d855e4/go.mod h1:VZulIr3aNvC/KDgO8BcYJheL9u5YNd0X43l4kLNd8t0=
github.com/xuri/nfp v0.0.0-20230503010013-3f38cdbb0b83 h1:xVwnvkzzi+OiwhIkWOXvh1skFI6bagk8OvGuazM80Rw=
github.com/xuri/nfp v0.0.0-20230503010013-3f38cdbb0b83/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
golang.org/x/image v0.5.0 h1:5JMiNunQeQw++mMOz48/ISeNu3Iweh/JaZU8ZLqHRrI=
golang.org/x/image v0.5.0/go.mod h1:FVC7BI/5Ym8R25iw5OLsgshdUBbT1h5jZTpA+mvAdZ4=
golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw=
golang.org/x/image v0.7.0/go.mod h1:nd/q4ef1AKKYl/4kft7g+6UyGbdiqWqTP1ZAbRoV7Rg=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -49,12 +48,10 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down
25 changes: 25 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ func regInteropFunc(f *excelize.File, fn map[string]interface{}) interface{} {
"GetDocProps": GetDocProps(f),
"GetPageLayout": GetPageLayout(f),
"GetPageMargins": GetPageMargins(f),
"GetPanes": GetPanes(f),
"GetPictures": GetPictures(f),
"GetRowHeight": GetRowHeight(f),
"GetRowOutlineLevel": GetRowOutlineLevel(f),
Expand Down Expand Up @@ -1867,6 +1868,30 @@ func GetPageMargins(f *excelize.File) func(this js.Value, args []js.Value) inter
}
}

// GetPanes provides a function to get freeze panes, split panes, and worksheet
// views by given worksheet name.
func GetPanes(f *excelize.File) func(this js.Value, args []js.Value) interface{} {
return func(this js.Value, args []js.Value) interface{} {
ret := map[string]interface{}{"panes": 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)
}
opts, err := f.GetPanes(args[0].String())
if err != nil {
ret["error"] = err.Error()
return js.ValueOf(ret)
}
if jsVal, err := goValueToJS(reflect.ValueOf(opts),
reflect.TypeOf(excelize.Panes{})); err == nil {
ret["panes"] = jsVal
}
return js.ValueOf(ret)
}
}

// GetPictures provides a function to get picture meta info and raw content
// embed in spreadsheet by given worksheet and cell name. This function
// returns the image contents as []byte data types.
Expand Down
13 changes: 12 additions & 1 deletion cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1998,7 +1998,7 @@ func TestPageMargins(t *testing.T) {
assert.Equal(t, "sheet SheetN does not exist", ret.Get("error").String())
}

func TestSetPanes(t *testing.T) {
func TestPanes(t *testing.T) {
f := NewFile(js.Value{}, []js.Value{})
assert.True(t, f.(js.Value).Get("error").IsNull())

Expand All @@ -2010,6 +2010,11 @@ func TestSetPanes(t *testing.T) {
)
assert.True(t, ret.Get("error").IsNull())

ret = f.(js.Value).Call("GetPanes", js.ValueOf("Sheet1"))
assert.True(t, ret.Get("error").IsNull())
assert.False(t, ret.Get("panes").Get("Freeze").Bool())
assert.False(t, ret.Get("panes").Get("Split").Bool())

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

Expand All @@ -2020,13 +2025,19 @@ func TestSetPanes(t *testing.T) {
)
assert.EqualError(t, errArgType, ret.Get("error").String())

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

ret = f.(js.Value).Call("SetPanes", js.ValueOf("SheetN"),
js.ValueOf(map[string]interface{}{
"Freeze": false,
"Split": false,
}),
)
assert.Equal(t, "sheet SheetN does not exist", ret.Get("error").String())

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

func TestSetRowHeight(t *testing.T) {
Expand Down
13 changes: 10 additions & 3 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ declare module 'excelize-wasm' {
};

/**
* PaneOptions directly maps the settings of the pane.
* Selection directly maps the settings of the worksheet selection.
*/
export type PaneOptions = {
export type Selection = {
SQRef?: string;
ActiveCell?: string;
Pane?: string;
Expand All @@ -175,7 +175,7 @@ declare module 'excelize-wasm' {
YSplit?: number;
TopLeftCell?: string;
ActivePane?: string;
Panes?: PaneOptions[];
Selection?: Selection[];
};

/**
Expand Down Expand Up @@ -1271,6 +1271,13 @@ declare module 'excelize-wasm' {
*/
GetPageLayout(sheet: string): { opts: PageLayoutOptions, error: string | null }

/**
* GetPanes provides a function to get freeze panes, split panes, and
* worksheet views by given worksheet name.
* @param sheet The worksheet name
*/
GetPanes(sheet: string): { panes: Panes, error: string | null }

/**
* GetPictures provides a function to get picture meta info and raw content
* embed in spreadsheet by given worksheet and cell name.
Expand Down

0 comments on commit e9ceb74

Please sign in to comment.