forked from p30928647/excelize
Number format read fix (#741)
* fix UT-generated file names to be ignored * fix cell value load with invalid number format ID * fix PR issues
This commit is contained in:
parent
95d8920c8e
commit
61057c58d3
|
@ -1,6 +1,10 @@
|
|||
~$*.xlsx
|
||||
test/Test*.xlsx
|
||||
test/Test*.xlsm
|
||||
# generated files
|
||||
test/BadEncrypt.xlsx
|
||||
test/BadWorkbook.SaveAsEmptyStruct.xlsx
|
||||
test/*.png
|
||||
*.out
|
||||
*.test
|
||||
.idea
|
||||
|
|
7
cell.go
7
cell.go
|
@ -762,10 +762,15 @@ func (f *File) formattedValue(s int, v string) string {
|
|||
return v
|
||||
}
|
||||
styleSheet := f.stylesReader()
|
||||
|
||||
if s >= len(styleSheet.CellXfs.Xf) {
|
||||
return v
|
||||
}
|
||||
numFmtID := *styleSheet.CellXfs.Xf[s].NumFmtID
|
||||
var numFmtID int
|
||||
if styleSheet.CellXfs.Xf[s].NumFmtID != nil {
|
||||
numFmtID = *styleSheet.CellXfs.Xf[s].NumFmtID
|
||||
}
|
||||
|
||||
ok := builtInNumFmtFunc[numFmtID]
|
||||
if ok != nil {
|
||||
return ok(v, builtInNumFmt[numFmtID])
|
||||
|
|
18
cell_test.go
18
cell_test.go
|
@ -301,7 +301,7 @@ func TestSetCellRichText(t *testing.T) {
|
|||
assert.EqualError(t, f.SetCellRichText("Sheet1", "A", richTextRun), `cannot convert cell "A" to coordinates: invalid cell name "A"`)
|
||||
}
|
||||
|
||||
func TestFormattedValue(t *testing.T) {
|
||||
func TestFormattedValue2(t *testing.T) {
|
||||
f := NewFile()
|
||||
v := f.formattedValue(0, "43528")
|
||||
assert.Equal(t, "43528", v)
|
||||
|
@ -320,12 +320,24 @@ func TestFormattedValue(t *testing.T) {
|
|||
assert.Equal(t, "03/04/2019", v)
|
||||
|
||||
// formatted value with no built-in number format ID
|
||||
assert.NoError(t, err)
|
||||
f.Styles.NumFmts = nil
|
||||
numFmtID := 5
|
||||
f.Styles.CellXfs.Xf = append(f.Styles.CellXfs.Xf, xlsxXf{
|
||||
NumFmtID: &numFmtID,
|
||||
})
|
||||
v = f.formattedValue(2, "43528")
|
||||
assert.Equal(t, "43528", v)
|
||||
|
||||
// formatted value with invalid number format ID
|
||||
f.Styles.CellXfs.Xf = append(f.Styles.CellXfs.Xf, xlsxXf{
|
||||
NumFmtID: nil,
|
||||
})
|
||||
v = f.formattedValue(3, "43528")
|
||||
|
||||
// formatted value with empty number format
|
||||
f.Styles.NumFmts = nil
|
||||
f.Styles.CellXfs.Xf = append(f.Styles.CellXfs.Xf, xlsxXf{
|
||||
NumFmtID: &numFmtID,
|
||||
})
|
||||
v = f.formattedValue(1, "43528")
|
||||
assert.Equal(t, "43528", v)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue