Skip to content

Commit

Permalink
feat: add locale const & lcid infos
Browse files Browse the repository at this point in the history
  • Loading branch information
fudali113 committed Apr 21, 2023
1 parent 3737ba4 commit 1636069
Show file tree
Hide file tree
Showing 5 changed files with 6,720 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,7 @@ func (f *File) formattedValue(c *xlsxC, raw bool, cellType CellType) (string, er
func (f *File) getBuiltInNumFmtCode(numFmtId int) string {
locale := ""
if f.options != nil {
locale = f.options.Locale
locale = strings.ToLower(string(f.options.Locale))
}
numFmtCode := builtInNumFmt[numFmtId]
if locale == "" {
Expand Down
21 changes: 2 additions & 19 deletions cell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,23 +877,6 @@ func TestFormattedValue(t *testing.T) {
assert.Equal(t, "0_0", fn("0_0", "", false, CellTypeNumber))
}

// Test format value with built-in number format ID = 14
styleID, err = f.NewStyle(&Style{
NumFmt: 14,
})
assert.NoError(t, err)
result, err = f.formattedValue(&xlsxC{S: styleID, V: "43528"}, false, CellTypeNumber)
assert.NoError(t, err)
assert.Equal(t, "03-04-19", result)
originalFileOptions := f.options
f.options = &Options{
Locale: "zh-cn",
}
result, err = f.formattedValue(&xlsxC{S: styleID, V: "43528"}, false, CellTypeNumber)
assert.NoError(t, err)
assert.Equal(t, "2019/3/4", result)
f.options = originalFileOptions

// Test format value with built-in number format zh-cn
styleID31, err := f.NewStyle(&Style{
NumFmt: 31,
Expand All @@ -905,9 +888,9 @@ func TestFormattedValue(t *testing.T) {
Lang: "zh-cn",
})
assert.NoError(t, err)
originalFileOptions = f.options
originalFileOptions := f.options
f.options = &Options{
Locale: "zh-cn",
Locale: ZH_CN,
}
result, err = f.formattedValue(&xlsxC{S: styleID31, V: "43528"}, false, CellTypeNumber)
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion excelize.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type Options struct {
RawCellValue bool
UnzipSizeLimit int64
UnzipXMLSizeLimit int64
Locale string
Locale Locale
}

// OpenFile take the name of an spreadsheet file and returns a populated
Expand Down
Loading

0 comments on commit 1636069

Please sign in to comment.