Skip to content

Commit

Permalink
Bump version v0.0.7
Browse files Browse the repository at this point in the history
- New function `GetCellType` has been added
- Add new CellType enumeration type values
- Upgrade the Excelize library version
- Update the unit tests and documentation
  • Loading branch information
xuri committed Oct 26, 2024
1 parent b5216e2 commit 8eed580
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/stretchr/testify v1.8.4
github.com/xuri/excelize/v2 v2.9.1-0.20241021013604-d1937a0cde23
github.com/xuri/excelize/v2 v2.9.1-0.20241025005259-0d5d1c53b2bd
golang.org/x/image v0.21.0
)

Expand Down
4 changes: 2 additions & 2 deletions cmd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d h1:llb0neMWDQe87IzJLS4Ci7psK/lVsjIS2otl+1WyRyY=
github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
github.com/xuri/excelize/v2 v2.9.1-0.20241021013604-d1937a0cde23 h1:+p06nEmhW37XGxhLvSWofLt1G9w+z2AbdHLz04ovbdU=
github.com/xuri/excelize/v2 v2.9.1-0.20241021013604-d1937a0cde23/go.mod h1:uqey4QBZ9gdMeWApPLdhm9x+9o2lq4iVmjiLfBS5hdE=
github.com/xuri/excelize/v2 v2.9.1-0.20241025005259-0d5d1c53b2bd h1:MI1Md1guoYC7X9UvvR9PUmO4HMZQIsL62I8TnxUoq9s=
github.com/xuri/excelize/v2 v2.9.1-0.20241025005259-0d5d1c53b2bd/go.mod h1:uqey4QBZ9gdMeWApPLdhm9x+9o2lq4iVmjiLfBS5hdE=
github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7 h1:hPVCafDV85blFTabnqKgNhDCkJX25eik94Si9cTER4A=
github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
Expand Down
33 changes: 33 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ func regConstants() {
"CultureNameKoKR": int(excelize.CultureNameKoKR),
"CultureNameZhCN": int(excelize.CultureNameZhCN),
"CultureNameZhTW": int(excelize.CultureNameZhTW),
// CellType enumeration
"CellTypeUnset": int(excelize.CellTypeUnset),
"CellTypeBool": int(excelize.CellTypeBool),
"CellTypeDate": int(excelize.CellTypeDate),
"CellTypeError": int(excelize.CellTypeError),
"CellTypeFormula": int(excelize.CellTypeFormula),
"CellTypeInlineString": int(excelize.CellTypeInlineString),
"CellTypeNumber": int(excelize.CellTypeNumber),
"CellTypeSharedString": int(excelize.CellTypeSharedString),
// FormControlType enumeration
"FormControlNote": int(excelize.FormControlNote),
"FormControlButton": int(excelize.FormControlButton),
Expand Down Expand Up @@ -327,6 +336,7 @@ func regInteropFunc(f *excelize.File, fn map[string]interface{}) interface{} {
"GetCellHyperLink": GetCellHyperLink(f),
"GetCellRichText": GetCellRichText(f),
"GetCellStyle": GetCellStyle(f),
"GetCellType": GetCellType(f),
"GetCellValue": GetCellValue(f),
"GetColOutlineLevel": GetColOutlineLevel(f),
"GetCols": GetCols(f),
Expand Down Expand Up @@ -1788,6 +1798,29 @@ func GetCellStyle(f *excelize.File) func(this js.Value, args []js.Value) interfa
}
}

// GetCellType provides a function to get the cell's data type by given
// worksheet name and cell reference in spreadsheet file.
func GetCellType(f *excelize.File) func(this js.Value, args []js.Value) interface{} {
return func(this js.Value, args []js.Value) interface{} {
ret := map[string]interface{}{"cellType": 0, "error": nil}
err := prepareArgs(args, []argsRule{
{types: []js.Type{js.TypeString}},
{types: []js.Type{js.TypeString}},
})
if err != nil {
ret["error"] = err.Error()
return js.ValueOf(ret)
}
var cellType excelize.CellType
cellType, err = f.GetCellType(args[0].String(), args[1].String())
if err != nil {
ret["error"] = err.Error()
}
ret["cellType"] = int(cellType)
return js.ValueOf(ret)
}
}

// GetCellValue provides a function to get formatted value from cell by given
// worksheet name and cell reference in spreadsheet. The return value is
// converted to the `string` data type. If the cell format can be applied to
Expand Down
23 changes: 23 additions & 0 deletions cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,29 @@ func TestGetCellStyle(t *testing.T) {
assert.Equal(t, 0, ret.Get("style").Int())
}

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

ret := f.(js.Value).Call("GetCellType", js.ValueOf("Sheet1"), js.ValueOf("A1"))
assert.True(t, ret.Get("error").IsNull())
assert.Equal(t, 0, ret.Get("cellType").Int())

ret = f.(js.Value).Call("SetCellValue", js.ValueOf("Sheet1"), js.ValueOf("A1"), js.ValueOf(true))
assert.True(t, ret.Get("error").IsNull())

ret = f.(js.Value).Call("GetCellType", js.ValueOf("Sheet1"), js.ValueOf("A1"))
assert.True(t, ret.Get("error").IsNull())
assert.Equal(t, 1, ret.Get("cellType").Int())

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

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

func TestGetCellValue(t *testing.T) {
f := NewFile(js.Value{}, []js.Value{})
assert.True(t, f.(js.Value).Get("error").IsNull())
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "excelize-wasm",
"version": "0.0.6",
"version": "0.0.7",
"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",
"author": "xuri <[email protected]>",
"homepage": "https://xuri.me/excelize",
Expand Down
30 changes: 30 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@ declare module 'excelize-wasm' {
CultureNameZhTW,
}

/**
* This section defines the cell value types enumeration.
*/
export enum CellType {
CellTypeUnset,
CellTypeBool,
CellTypeDate,
CellTypeError,
CellTypeFormula,
CellTypeInlineString,
CellTypeNumber,
CellTypeSharedString,
}

/**
* FormControlType is the type of supported form controls.
*/
Expand Down Expand Up @@ -2097,6 +2111,14 @@ declare module 'excelize-wasm' {
*/
GetCellStyle(sheet: string, cell: string): { style: number, error: string | null }

/**
* GetCellType provides a function to get the cell's data type by given
* worksheet name and cell reference in spreadsheet file.
* @param sheet The worksheet name
* @param cell The cell reference
*/
GetCellStyle(sheet: string, cell: string): { cellType: CellType, error: string | null }

/**
* GetCellValue provides a function to get formatted value from cell by
* given worksheet name and cell reference in spreadsheet. The return value
Expand Down Expand Up @@ -3651,6 +3673,14 @@ declare module 'excelize-wasm' {
ThemeColor: typeof ThemeColor,
NewFile: typeof NewFile;
OpenReader: typeof OpenReader;
CellTypeUnset: typeof CellType.CellTypeUnset;
CellTypeBool: typeof CellType.CellTypeBool;
CellTypeDate: typeof CellType.CellTypeDate;
CellTypeError: typeof CellType.CellTypeError;
CellTypeFormula: typeof CellType.CellTypeFormula;
CellTypeInlineString: typeof CellType.CellTypeInlineString;
CellTypeNumber: typeof CellType.CellTypeNumber;
CellTypeSharedString: typeof CellType.CellTypeSharedString;
CultureNameUnknown: typeof CultureName.CultureNameUnknown;
CultureNameEnUS: typeof CultureName.CultureNameEnUS;
CultureNameJaJP: typeof CultureName.CultureNameJaJP;
Expand Down

0 comments on commit 8eed580

Please sign in to comment.