Skip to content

Commit 661c0ea

Browse files
committed
Support apply built-in number format code 22 with custom short date pattern
1 parent 121ac17 commit 661c0ea

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

excelize_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,16 @@ func TestSetCellStyleNumberFormat(t *testing.T) {
783783
assert.NoError(t, f.SetCellStyle("Sheet2", "L33", "L33", style))
784784

785785
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestSetCellStyleNumberFormat.xlsx")))
786+
787+
// Test get cell value with built-in number format code 22 with custom short date pattern
788+
f = NewFile(Options{ShortDatePattern: "yyyy-m-dd"})
789+
assert.NoError(t, f.SetCellValue("Sheet1", "A1", 45074.625694444447))
790+
style, err = f.NewStyle(&Style{NumFmt: 22})
791+
assert.NoError(t, err)
792+
assert.NoError(t, f.SetCellStyle("Sheet1", "A1", "A1", style))
793+
cellValue, err := f.GetCellValue("Sheet1", "A1")
794+
assert.NoError(t, err)
795+
assert.Equal(t, "2023-5-28 15:01", cellValue)
786796
}
787797

788798
func TestSetCellStyleCurrencyNumberFormat(t *testing.T) {

numfmt.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,9 @@ func (f *File) langNumFmtFuncZhCN(numFmtID int) string {
10731073
// getBuiltInNumFmtCode convert number format index to number format code with
10741074
// specified locale and language.
10751075
func (f *File) getBuiltInNumFmtCode(numFmtID int) (string, bool) {
1076+
if numFmtID == 22 && f.options.ShortDatePattern != "" {
1077+
return fmt.Sprintf("%s hh:mm", f.options.ShortDatePattern), true
1078+
}
10761079
if fmtCode, ok := builtInNumFmt[numFmtID]; ok {
10771080
return fmtCode, true
10781081
}

0 commit comments

Comments
 (0)