Skip to content

Commit 7120303

Browse files
authored
This closes #46, new function GetDataValidations has been added (#5)
- Update unit tests - Upgrade the dependencies package version - Use OpenID Connect (OIDC) trusted publishing for NPM package - Bump v0.1.1
1 parent 990dd34 commit 7120303

File tree

9 files changed

+77
-26
lines changed

9 files changed

+77
-26
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565

6666
- name: NPM Build
6767
run: |
68-
npm install
68+
npm ci
6969
node ./node_modules/.bin/rollup -c
7070
cp LICENSE ./dist
7171
cp README.md ./dist

.github/workflows/publish.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ jobs:
1818
GOOS: js
1919
GOARCH: wasm
2020
GO111MODULE: on
21+
permissions:
22+
contents: read
23+
id-token: write
2124
steps:
2225

2326
- name: Install Go
@@ -58,19 +61,20 @@ jobs:
5861
- name: Setup Node.js
5962
uses: actions/setup-node@v6
6063
with:
61-
node-version: 20.18.1
64+
node-version: 20.19.6
65+
registry-url: 'https://registry.npmjs.org'
6266

6367
- name: NPM Build
6468
run: |
65-
npm install
69+
npm install -g npm@latest
70+
npm ci
6671
node ./node_modules/.bin/rollup -c
6772
cp LICENSE ./dist
6873
cp README.md ./dist
6974
cp package.json ./dist
7075
cp src/index.d.ts ./dist
76+
npm publish
7177
7278
- name: NPM Publish
73-
uses: JS-DevTools/npm-publish@v4
74-
with:
75-
token: ${{ secrets.NPM_TOKEN }}
76-
package: ./dist/package.json
79+
run: |
80+
npm publish

cmd/go.mod

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

55
require (
66
github.com/stretchr/testify v1.11.1
7-
github.com/xuri/excelize/v2 v2.10.1-0.20251128004124-f1ac51e63bc8
8-
golang.org/x/image v0.33.0
7+
github.com/xuri/excelize/v2 v2.10.1-0.20251212004743-418be6db1900
8+
golang.org/x/image v0.34.0
99
)
1010

1111
require (
@@ -16,8 +16,8 @@ require (
1616
github.com/tiendc/go-deepcopy v1.7.2 // indirect
1717
github.com/xuri/efp v0.0.1 // indirect
1818
github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9 // indirect
19-
golang.org/x/crypto v0.45.0 // indirect
20-
golang.org/x/net v0.47.0 // indirect
21-
golang.org/x/text v0.31.0 // indirect
19+
golang.org/x/crypto v0.46.0 // indirect
20+
golang.org/x/net v0.48.0 // indirect
21+
golang.org/x/text v0.32.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
@@ -13,18 +13,18 @@ github.com/tiendc/go-deepcopy v1.7.2 h1:Ut2yYR7W9tWjTQitganoIue4UGxZwCcJy3orjrrI
1313
github.com/tiendc/go-deepcopy v1.7.2/go.mod h1:4bKjNC2r7boYOkD2IOuZpYjmlDdzjbpTRyCx+goBCJQ=
1414
github.com/xuri/efp v0.0.1 h1:fws5Rv3myXyYni8uwj2qKjVaRP30PdjeYe2Y6FDsCL8=
1515
github.com/xuri/efp v0.0.1/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
16-
github.com/xuri/excelize/v2 v2.10.1-0.20251128004124-f1ac51e63bc8 h1:BMTZwsTDkAGubaojDitcn7jw+VbPCRT5vpV2C4eD/gY=
17-
github.com/xuri/excelize/v2 v2.10.1-0.20251128004124-f1ac51e63bc8/go.mod h1:B1Yl9Szv1D018lVoZttJ5lJkw8AP40Ysb0uKP4VO2hA=
16+
github.com/xuri/excelize/v2 v2.10.1-0.20251212004743-418be6db1900 h1:vtctSAFjYukuBb04Gb/1mTkJ5byBvlONEtiyNA1r/Gk=
17+
github.com/xuri/excelize/v2 v2.10.1-0.20251212004743-418be6db1900/go.mod h1:B1Yl9Szv1D018lVoZttJ5lJkw8AP40Ysb0uKP4VO2hA=
1818
github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9 h1:+C0TIdyyYmzadGaL/HBLbf3WdLgC29pgyhTjAT/0nuE=
1919
github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
20-
golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q=
21-
golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4=
22-
golang.org/x/image v0.33.0 h1:LXRZRnv1+zGd5XBUVRFmYEphyyKJjQjCRiOuAP3sZfQ=
23-
golang.org/x/image v0.33.0/go.mod h1:DD3OsTYT9chzuzTQt+zMcOlBHgfoKQb1gry8p76Y1sc=
24-
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
25-
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
26-
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
27-
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
20+
golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU=
21+
golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0=
22+
golang.org/x/image v0.34.0 h1:33gCkyw9hmwbZJeZkct8XyR11yH889EQt/QH4VmXMn8=
23+
golang.org/x/image v0.34.0/go.mod h1:2RNFBZRB+vnwwFil8GkMdRvrJOFd1AzdZI6vOY+eJVU=
24+
golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU=
25+
golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY=
26+
golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
27+
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ func regInteropFunc(f *excelize.File, fn map[string]interface{}) interface{} {
379379
"GetComments": GetComments(f),
380380
"GetConditionalStyle": GetConditionalStyle(f),
381381
"GetCustomProps": GetCustomProps(f),
382+
"GetDataValidations": GetDataValidations(f),
382383
"GetDefaultFont": GetDefaultFont(f),
383384
"GetDefinedName": GetDefinedName(f),
384385
"GetDocProps": GetDocProps(f),
@@ -2181,6 +2182,33 @@ func GetCustomProps(f *excelize.File) func(this js.Value, args []js.Value) inter
21812182
}
21822183
}
21832184

2185+
// GetDataValidations returns data validations list by given worksheet name.
2186+
func GetDataValidations(f *excelize.File) func(this js.Value, args []js.Value) interface{} {
2187+
return func(this js.Value, args []js.Value) interface{} {
2188+
ret := map[string]interface{}{"dataValidations": []interface{}{}, "error": nil}
2189+
if err := prepareArgs(args, []argsRule{
2190+
{types: []js.Type{js.TypeString}},
2191+
}); err != nil {
2192+
ret["error"] = err.Error()
2193+
return js.ValueOf(ret)
2194+
}
2195+
dataValidations, err := f.GetDataValidations(args[0].String())
2196+
if err != nil {
2197+
ret["error"] = err.Error()
2198+
return js.ValueOf(ret)
2199+
}
2200+
for _, dv := range dataValidations {
2201+
if jsVal, err := goValueToJS(reflect.ValueOf(*dv),
2202+
reflect.TypeOf(excelize.DataValidation{})); err == nil {
2203+
x := ret["dataValidations"].([]interface{})
2204+
x = append(x, jsVal)
2205+
ret["dataValidations"] = x
2206+
}
2207+
}
2208+
return js.ValueOf(ret)
2209+
}
2210+
}
2211+
21842212
// GetDefaultFont provides the default font name currently set in the
21852213
// workbook. The spreadsheet generated by excelize default font is Calibri.
21862214
func GetDefaultFont(f *excelize.File) func(this js.Value, args []js.Value) interface{} {

cmd/main_test.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ func TestComments(t *testing.T) {
423423
assert.Equal(t, "sheet SheetN does not exist", ret.Get("error").String())
424424
}
425425

426-
func TestAddDataValidation(t *testing.T) {
426+
func TestDataValidation(t *testing.T) {
427427
f := NewFile(js.Value{}, []js.Value{})
428428
assert.True(t, f.(js.Value).Get("error").IsNull())
429429
dv := js.ValueOf(map[string]interface{}{})
@@ -442,6 +442,19 @@ func TestAddDataValidation(t *testing.T) {
442442

443443
ret = f.(js.Value).Call("AddDataValidation", js.ValueOf("SheetN"), dv)
444444
assert.Equal(t, "sheet SheetN does not exist", ret.Get("error").String())
445+
446+
ret = f.(js.Value).Call("GetDataValidations", js.ValueOf("Sheet1"))
447+
assert.True(t, ret.Get("error").IsNull())
448+
assert.Equal(t, ret.Get("dataValidations").Length(), 1)
449+
450+
ret = f.(js.Value).Call("GetDataValidations")
451+
assert.EqualError(t, errArgNum, ret.Get("error").String())
452+
453+
ret = f.(js.Value).Call("GetDataValidations", js.ValueOf(nil))
454+
assert.Equal(t, errArgType.Error(), ret.Get("error").String())
455+
456+
ret = f.(js.Value).Call("GetDataValidations", js.ValueOf("SheetN"))
457+
assert.Equal(t, "sheet SheetN does not exist", ret.Get("error").String())
445458
}
446459

447460
func TestFormControl(t *testing.T) {

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "excelize-wasm",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "A pure WebAssembly / Javascript port of Go Excelize library that allow you to write to and read from XLAM / XLSM / XLSX / XLTM / XLTX files",
55
"author": "xuri <xuri.me@gmail.com>",
66
"homepage": "https://xuri.me/excelize",

src/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,6 +2430,12 @@ declare module 'excelize-wasm' {
24302430
*/
24312431
GetCustomProps(): { props: CustomProperty[], error: string | null }
24322432

2433+
/**
2434+
* GetDataValidations returns data validations list by given worksheet name.
2435+
* @param sheet The worksheet name
2436+
*/
2437+
GetDataValidations(sheet: string): { dataValidation: DataValidation[], error: string | null }
2438+
24332439
/**
24342440
* GetDefaultFont provides the default font name currently set in the
24352441
* workbook. The spreadsheet generated by excelize default font is Calibri.

0 commit comments

Comments
 (0)