Skip to content

Commit c963d99

Browse files
committed
New function GetCalcProps has been added
- Update unit tests
1 parent 241c6e7 commit c963d99

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

cmd/main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ func regInteropFunc(f *excelize.File, fn map[string]interface{}) interface{} {
349349
"GetActiveSheetIndex": GetActiveSheetIndex(f),
350350
"GetAppProps": GetAppProps(f),
351351
"GetBaseColor": GetBaseColor(f),
352+
"GetCalcProps": GetCalcProps(f),
352353
"GetCellFormula": GetCellFormula(f),
353354
"GetCellHyperLink": GetCellHyperLink(f),
354355
"GetCellRichText": GetCellRichText(f),
@@ -1794,6 +1795,27 @@ func GetBaseColor(f *excelize.File) func(this js.Value, args []js.Value) interfa
17941795
}
17951796
}
17961797

1798+
// GetCalcProps provides a function to gets calculation properties.
1799+
func GetCalcProps(f *excelize.File) func(this js.Value, args []js.Value) interface{} {
1800+
return func(this js.Value, args []js.Value) interface{} {
1801+
ret := map[string]interface{}{"props": map[string]interface{}{}, "error": nil}
1802+
if err := prepareArgs(args, []argsRule{}); err != nil {
1803+
ret["error"] = err.Error()
1804+
return js.ValueOf(ret)
1805+
}
1806+
props, err := f.GetCalcProps()
1807+
if err != nil {
1808+
ret["error"] = err.Error()
1809+
return js.ValueOf(ret)
1810+
}
1811+
if jsVal, err := goValueToJS(reflect.ValueOf(props),
1812+
reflect.TypeOf(excelize.CalcPropsOptions{})); err == nil {
1813+
ret["props"] = jsVal
1814+
}
1815+
return js.ValueOf(ret)
1816+
}
1817+
}
1818+
17971819
// GetCellFormula provides a function to get formula from cell by given
17981820
// worksheet name and cell reference in spreadsheet.
17991821
func GetCellFormula(f *excelize.File) func(this js.Value, args []js.Value) interface{} {

cmd/main_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -948,16 +948,26 @@ func TestCalcProps(t *testing.T) {
948948
)
949949
assert.True(t, ret.Get("error").IsNull())
950950

951+
ret = f.(js.Value).Call("GetCalcProps")
952+
assert.True(t, ret.Get("error").IsNull(), ret.Get("error").String())
953+
assert.True(t, ret.Get("props").Get("FullCalcOnLoad").Bool())
954+
assert.Equal(t, 122211, ret.Get("props").Get("CalcID").Int())
955+
assert.Equal(t, 5, ret.Get("props").Get("ConcurrentManualCount").Int())
956+
assert.Equal(t, 10, ret.Get("props").Get("IterateCount").Int())
957+
assert.True(t, ret.Get("props").Get("ConcurrentCalc").Bool())
958+
assert.True(t, ret.Get("props").Get("ForceFullCalc").IsUndefined())
959+
960+
ret = f.(js.Value).Call("GetCalcProps", js.ValueOf(map[string]interface{}{"CalcMode": true}))
961+
assert.EqualError(t, errArgNum, ret.Get("error").String())
962+
951963
ret = f.(js.Value).Call("SetCalcProps", js.ValueOf(map[string]interface{}{"RefMode": "a1"}))
952964
assert.Equal(t, "invalid RefMode value \"a1\", acceptable value should be one of A1, R1C1", ret.Get("error").String())
953965

954966
ret = f.(js.Value).Call("SetCalcProps")
955967
assert.EqualError(t, errArgNum, ret.Get("error").String())
956968

957969
ret = f.(js.Value).Call("SetCalcProps",
958-
js.ValueOf(map[string]interface{}{
959-
"CalcMode": true,
960-
}),
970+
js.ValueOf(map[string]interface{}{"CalcMode": true}),
961971
)
962972
assert.EqualError(t, errArgType, ret.Get("error").String())
963973
}

src/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,6 +2213,11 @@ declare module 'excelize-wasm' {
22132213
*/
22142214
GetBaseColor(hexColor: string, indexedColor: number, themeColor?: number): { color?: string, error: string | null };
22152215

2216+
/**
2217+
* GetCalcProps provides a function to gets calculation properties.
2218+
*/
2219+
GetCalcProps(): { props: CalcPropsOptions, error: string | null }
2220+
22162221
/**
22172222
* GetCellFormula provides a function to get formula from cell by given
22182223
* worksheet name and cell reference in spreadsheet.

0 commit comments

Comments
 (0)