Skip to content

Commit 8eed580

Browse files
committed
Bump version v0.0.7
- New function `GetCellType` has been added - Add new CellType enumeration type values - Upgrade the Excelize library version - Update the unit tests and documentation
1 parent b5216e2 commit 8eed580

File tree

7 files changed

+92
-6
lines changed

7 files changed

+92
-6
lines changed

cmd/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.18
44

55
require (
66
github.com/stretchr/testify v1.8.4
7-
github.com/xuri/excelize/v2 v2.9.1-0.20241021013604-d1937a0cde23
7+
github.com/xuri/excelize/v2 v2.9.1-0.20241025005259-0d5d1c53b2bd
88
golang.org/x/image v0.21.0
99
)
1010

cmd/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
1313
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
1414
github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d h1:llb0neMWDQe87IzJLS4Ci7psK/lVsjIS2otl+1WyRyY=
1515
github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
16-
github.com/xuri/excelize/v2 v2.9.1-0.20241021013604-d1937a0cde23 h1:+p06nEmhW37XGxhLvSWofLt1G9w+z2AbdHLz04ovbdU=
17-
github.com/xuri/excelize/v2 v2.9.1-0.20241021013604-d1937a0cde23/go.mod h1:uqey4QBZ9gdMeWApPLdhm9x+9o2lq4iVmjiLfBS5hdE=
16+
github.com/xuri/excelize/v2 v2.9.1-0.20241025005259-0d5d1c53b2bd h1:MI1Md1guoYC7X9UvvR9PUmO4HMZQIsL62I8TnxUoq9s=
17+
github.com/xuri/excelize/v2 v2.9.1-0.20241025005259-0d5d1c53b2bd/go.mod h1:uqey4QBZ9gdMeWApPLdhm9x+9o2lq4iVmjiLfBS5hdE=
1818
github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7 h1:hPVCafDV85blFTabnqKgNhDCkJX25eik94Si9cTER4A=
1919
github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
2020
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=

cmd/main.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ func regConstants() {
197197
"CultureNameKoKR": int(excelize.CultureNameKoKR),
198198
"CultureNameZhCN": int(excelize.CultureNameZhCN),
199199
"CultureNameZhTW": int(excelize.CultureNameZhTW),
200+
// CellType enumeration
201+
"CellTypeUnset": int(excelize.CellTypeUnset),
202+
"CellTypeBool": int(excelize.CellTypeBool),
203+
"CellTypeDate": int(excelize.CellTypeDate),
204+
"CellTypeError": int(excelize.CellTypeError),
205+
"CellTypeFormula": int(excelize.CellTypeFormula),
206+
"CellTypeInlineString": int(excelize.CellTypeInlineString),
207+
"CellTypeNumber": int(excelize.CellTypeNumber),
208+
"CellTypeSharedString": int(excelize.CellTypeSharedString),
200209
// FormControlType enumeration
201210
"FormControlNote": int(excelize.FormControlNote),
202211
"FormControlButton": int(excelize.FormControlButton),
@@ -327,6 +336,7 @@ func regInteropFunc(f *excelize.File, fn map[string]interface{}) interface{} {
327336
"GetCellHyperLink": GetCellHyperLink(f),
328337
"GetCellRichText": GetCellRichText(f),
329338
"GetCellStyle": GetCellStyle(f),
339+
"GetCellType": GetCellType(f),
330340
"GetCellValue": GetCellValue(f),
331341
"GetColOutlineLevel": GetColOutlineLevel(f),
332342
"GetCols": GetCols(f),
@@ -1788,6 +1798,29 @@ func GetCellStyle(f *excelize.File) func(this js.Value, args []js.Value) interfa
17881798
}
17891799
}
17901800

1801+
// GetCellType provides a function to get the cell's data type by given
1802+
// worksheet name and cell reference in spreadsheet file.
1803+
func GetCellType(f *excelize.File) func(this js.Value, args []js.Value) interface{} {
1804+
return func(this js.Value, args []js.Value) interface{} {
1805+
ret := map[string]interface{}{"cellType": 0, "error": nil}
1806+
err := prepareArgs(args, []argsRule{
1807+
{types: []js.Type{js.TypeString}},
1808+
{types: []js.Type{js.TypeString}},
1809+
})
1810+
if err != nil {
1811+
ret["error"] = err.Error()
1812+
return js.ValueOf(ret)
1813+
}
1814+
var cellType excelize.CellType
1815+
cellType, err = f.GetCellType(args[0].String(), args[1].String())
1816+
if err != nil {
1817+
ret["error"] = err.Error()
1818+
}
1819+
ret["cellType"] = int(cellType)
1820+
return js.ValueOf(ret)
1821+
}
1822+
}
1823+
17911824
// GetCellValue provides a function to get formatted value from cell by given
17921825
// worksheet name and cell reference in spreadsheet. The return value is
17931826
// converted to the `string` data type. If the cell format can be applied to

cmd/main_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,29 @@ func TestGetCellStyle(t *testing.T) {
10941094
assert.Equal(t, 0, ret.Get("style").Int())
10951095
}
10961096

1097+
func TestGetCellType(t *testing.T) {
1098+
f := NewFile(js.Value{}, []js.Value{})
1099+
assert.True(t, f.(js.Value).Get("error").IsNull())
1100+
1101+
ret := f.(js.Value).Call("GetCellType", js.ValueOf("Sheet1"), js.ValueOf("A1"))
1102+
assert.True(t, ret.Get("error").IsNull())
1103+
assert.Equal(t, 0, ret.Get("cellType").Int())
1104+
1105+
ret = f.(js.Value).Call("SetCellValue", js.ValueOf("Sheet1"), js.ValueOf("A1"), js.ValueOf(true))
1106+
assert.True(t, ret.Get("error").IsNull())
1107+
1108+
ret = f.(js.Value).Call("GetCellType", js.ValueOf("Sheet1"), js.ValueOf("A1"))
1109+
assert.True(t, ret.Get("error").IsNull())
1110+
assert.Equal(t, 1, ret.Get("cellType").Int())
1111+
1112+
ret = f.(js.Value).Call("GetCellType")
1113+
assert.EqualError(t, errArgNum, ret.Get("error").String())
1114+
1115+
ret = f.(js.Value).Call("GetCellType", js.ValueOf("SheetN"), js.ValueOf("A1"))
1116+
assert.Equal(t, "sheet SheetN does not exist", ret.Get("error").String())
1117+
assert.Equal(t, 0, ret.Get("cellType").Int())
1118+
}
1119+
10971120
func TestGetCellValue(t *testing.T) {
10981121
f := NewFile(js.Value{}, []js.Value{})
10991122
assert.True(t, f.(js.Value).Get("error").IsNull())

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.0.6",
3+
"version": "0.0.7",
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 <[email protected]>",
66
"homepage": "https://xuri.me/excelize",

src/index.d.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ declare module 'excelize-wasm' {
3737
CultureNameZhTW,
3838
}
3939

40+
/**
41+
* This section defines the cell value types enumeration.
42+
*/
43+
export enum CellType {
44+
CellTypeUnset,
45+
CellTypeBool,
46+
CellTypeDate,
47+
CellTypeError,
48+
CellTypeFormula,
49+
CellTypeInlineString,
50+
CellTypeNumber,
51+
CellTypeSharedString,
52+
}
53+
4054
/**
4155
* FormControlType is the type of supported form controls.
4256
*/
@@ -2097,6 +2111,14 @@ declare module 'excelize-wasm' {
20972111
*/
20982112
GetCellStyle(sheet: string, cell: string): { style: number, error: string | null }
20992113

2114+
/**
2115+
* GetCellType provides a function to get the cell's data type by given
2116+
* worksheet name and cell reference in spreadsheet file.
2117+
* @param sheet The worksheet name
2118+
* @param cell The cell reference
2119+
*/
2120+
GetCellStyle(sheet: string, cell: string): { cellType: CellType, error: string | null }
2121+
21002122
/**
21012123
* GetCellValue provides a function to get formatted value from cell by
21022124
* given worksheet name and cell reference in spreadsheet. The return value
@@ -3651,6 +3673,14 @@ declare module 'excelize-wasm' {
36513673
ThemeColor: typeof ThemeColor,
36523674
NewFile: typeof NewFile;
36533675
OpenReader: typeof OpenReader;
3676+
CellTypeUnset: typeof CellType.CellTypeUnset;
3677+
CellTypeBool: typeof CellType.CellTypeBool;
3678+
CellTypeDate: typeof CellType.CellTypeDate;
3679+
CellTypeError: typeof CellType.CellTypeError;
3680+
CellTypeFormula: typeof CellType.CellTypeFormula;
3681+
CellTypeInlineString: typeof CellType.CellTypeInlineString;
3682+
CellTypeNumber: typeof CellType.CellTypeNumber;
3683+
CellTypeSharedString: typeof CellType.CellTypeSharedString;
36543684
CultureNameUnknown: typeof CultureName.CultureNameUnknown;
36553685
CultureNameEnUS: typeof CultureName.CultureNameEnUS;
36563686
CultureNameJaJP: typeof CultureName.CultureNameJaJP;

0 commit comments

Comments
 (0)