Skip to content

Commit 59bf896

Browse files
authored
New function GetCustomProps has been added
- Add TmpDir field in the Options data type - Update unit tests - Upgrade the Excelize library version
1 parent be4648a commit 59bf896

File tree

5 files changed

+69
-7
lines changed

5 files changed

+69
-7
lines changed

cmd/go.mod

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

55
require (
66
github.com/stretchr/testify v1.10.0
7-
github.com/xuri/excelize/v2 v2.9.2-0.20250614235856-d434acdde46b
8-
golang.org/x/image v0.27.0
7+
github.com/xuri/excelize/v2 v2.9.2-0.20250625074405-55e152f8492f
8+
golang.org/x/image v0.28.0
99
)
1010

1111
require (

cmd/go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ github.com/tiendc/go-deepcopy v1.6.1 h1:uVRTItFeNHkMcLueHS7OCsxgxT9P8MzGB/taUa2Y
1313
github.com/tiendc/go-deepcopy v1.6.1/go.mod h1:toXoeQoUqXOOS/X4sKuiAoSk6elIdqc0pN7MTgOOo2I=
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.9.2-0.20250614235856-d434acdde46b h1:0+9AA5rFR07411NM9EdIagfecnG5weEFYgsiiPV/O+s=
17-
github.com/xuri/excelize/v2 v2.9.2-0.20250614235856-d434acdde46b/go.mod h1:isQygQdjiU88/HpJYtp+6TN/FH29HvVjWT8vFk3t5+w=
16+
github.com/xuri/excelize/v2 v2.9.2-0.20250625074405-55e152f8492f h1:ajRl2rx7253Gi6mpnfnoBe22xZF57Czyw7tDCWXgR00=
17+
github.com/xuri/excelize/v2 v2.9.2-0.20250625074405-55e152f8492f/go.mod h1:isQygQdjiU88/HpJYtp+6TN/FH29HvVjWT8vFk3t5+w=
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=
2020
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
2121
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
22-
golang.org/x/image v0.27.0 h1:C8gA4oWU/tKkdCfYT6T2u4faJu3MeNS5O8UPWlPF61w=
23-
golang.org/x/image v0.27.0/go.mod h1:xbdrClrAUway1MUTEZDq9mz/UpRwYAkFFNUslZtcB+g=
22+
golang.org/x/image v0.28.0 h1:gdem5JW1OLS4FbkWgLO+7ZeFzYtL3xClb97GaUzYMFE=
23+
golang.org/x/image v0.28.0/go.mod h1:GUJYXtnGKEUgggyzh+Vxt+AviiCcyiwpsl8iQ8MvwGY=
2424
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
2525
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
2626
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=

cmd/main.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ func regInteropFunc(f *excelize.File, fn map[string]interface{}) interface{} {
363363
"GetColWidth": GetColWidth(f),
364364
"GetComments": GetComments(f),
365365
"GetConditionalStyle": GetConditionalStyle(f),
366+
"GetCustomProps": GetCustomProps(f),
366367
"GetDefaultFont": GetDefaultFont(f),
367368
"GetDefinedName": GetDefinedName(f),
368369
"GetDocProps": GetDocProps(f),
@@ -2142,6 +2143,28 @@ func GetConditionalStyle(f *excelize.File) func(this js.Value, args []js.Value)
21422143
}
21432144
}
21442145

2146+
// GetCustomProps provides a function to get custom file properties.
2147+
func GetCustomProps(f *excelize.File) func(this js.Value, args []js.Value) interface{} {
2148+
return func(this js.Value, args []js.Value) interface{} {
2149+
ret := map[string]interface{}{"props": []interface{}{}, "error": nil}
2150+
if err := prepareArgs(args, []argsRule{}); err != nil {
2151+
ret["error"] = err.Error()
2152+
return js.ValueOf(ret)
2153+
}
2154+
props, err := f.GetCustomProps()
2155+
if err != nil {
2156+
ret["error"] = err.Error()
2157+
return js.ValueOf(ret)
2158+
}
2159+
for _, prop := range props {
2160+
x := ret["props"].([]interface{})
2161+
x = append(x, js.ValueOf(map[string]interface{}{"Name": prop.Name, "Value": prop.Value}))
2162+
ret["props"] = x
2163+
}
2164+
return js.ValueOf(ret)
2165+
}
2166+
}
2167+
21452168
// GetDefaultFont provides the default font name currently set in the
21462169
// workbook. The spreadsheet generated by excelize default font is Calibri.
21472170
func GetDefaultFont(f *excelize.File) func(this js.Value, args []js.Value) interface{} {

cmd/main_test.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2288,14 +2288,44 @@ func TestCustomProps(t *testing.T) {
22882288
assert.True(t, ret.Get("error").IsNull())
22892289
}
22902290

2291-
ret := f.(js.Value).Call("SetCustomProps")
2291+
ret := f.(js.Value).Call("GetCustomProps")
2292+
assert.Equal(t, ret.Get("props").Length(), 4)
2293+
assert.Equal(t, ret.Get("props").Index(0).Get("Value").String(), "text")
2294+
assert.True(t, ret.Get("props").Index(1).Get("Value").Bool())
2295+
assert.False(t, ret.Get("props").Index(2).Get("Value").Bool())
2296+
assert.Equal(t, ret.Get("props").Index(3).Get("Value").Float(), -123.456)
2297+
2298+
ret = f.(js.Value).Call("SetCustomProps")
22922299
assert.EqualError(t, errArgNum, ret.Get("error").String())
22932300

22942301
ret = f.(js.Value).Call("SetCustomProps", js.ValueOf(1))
22952302
assert.EqualError(t, errArgType, ret.Get("error").String())
22962303

22972304
ret = f.(js.Value).Call("SetCustomProps", js.ValueOf(map[string]interface{}{"Name": 1}))
22982305
assert.EqualError(t, errArgType, ret.Get("error").String())
2306+
2307+
ret = f.(js.Value).Call("GetCustomProps", js.ValueOf(1))
2308+
assert.EqualError(t, errArgNum, ret.Get("error").String())
2309+
2310+
// Test get custom property with unsupported charset
2311+
wb := excelize.NewFile()
2312+
wb.Sheet.Delete("docProps/custom.xml")
2313+
wb.Pkg.Store("docProps/custom.xml", MacintoshCyrillicCharset)
2314+
buf, err := wb.WriteToBuffer()
2315+
assert.NoError(t, err)
2316+
2317+
uint8Array := js.Global().Get("Uint8Array").New(js.ValueOf(buf.Len()))
2318+
for k, v := range buf.Bytes() {
2319+
uint8Array.SetIndex(k, v)
2320+
}
2321+
f = OpenReader(js.Value{}, []js.Value{uint8Array})
2322+
assert.True(t, f.(js.Value).Get("error").IsNull())
2323+
ret = f.(js.Value).Call("GetCustomProps")
2324+
assert.Equal(t, ret.Get("error").String(), "XML syntax error on line 1: invalid UTF-8")
2325+
2326+
// Test set custom property with unsupported charset
2327+
ret = f.(js.Value).Call("SetCustomProps", js.ValueOf(map[string]interface{}{"Name": "Text Prop", "Value": "text"}))
2328+
assert.Equal(t, ret.Get("error").String(), "XML syntax error on line 1: invalid UTF-8")
22992329
}
23002330

23012331
func TestSetDefaultFont(t *testing.T) {

src/index.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,17 @@ declare module 'excelize-wasm' {
100100
*
101101
* CultureInfo specifies the country code for applying built-in language
102102
* number format code these effect by the system's local language settings.
103+
*
104+
* TmpDir specifies the temporary directory for creating temporary files, if
105+
* the value is empty, the system default temporary directory will be used.
103106
*/
104107
export type Options = {
105108
MaxCalcIterations?: number;
106109
Password?: string;
107110
RawCellValue?: boolean;
108111
UnzipSizeLimit?: number;
109112
UnzipXMLSizeLimit?: number;
113+
TmpDir?: string;
110114
ShortDatePattern?: string;
111115
LongDatePattern?: string;
112116
LongTimePattern?: string;
@@ -2353,6 +2357,11 @@ declare module 'excelize-wasm' {
23532357
*/
23542358
GetConditionalStyle(styleID: number): { style: Style, error: string | null }
23552359

2360+
/**
2361+
* GetCustomProps provides a function to get custom file properties.
2362+
*/
2363+
GetCustomProps(): { props: CustomProperty[], error: string | null }
2364+
23562365
/**
23572366
* GetDefaultFont provides the default font name currently set in the
23582367
* workbook. The spreadsheet generated by excelize default font is Calibri.

0 commit comments

Comments
 (0)