forked from p30928647/excelize
This closes #714 and closes #715, fix wrong worksheet index returned by NewSheet in some case, fix panic on formatted value with no built-in number format ID
This commit is contained in:
parent
520aa679f3
commit
4834a058aa
3
cell.go
3
cell.go
|
@ -770,6 +770,9 @@ func (f *File) formattedValue(s int, v string) string {
|
|||
if ok != nil {
|
||||
return ok(v, builtInNumFmt[numFmtId])
|
||||
}
|
||||
if styleSheet == nil || styleSheet.NumFmts == nil {
|
||||
return v
|
||||
}
|
||||
for _, xlsxFmt := range styleSheet.NumFmts.NumFmt {
|
||||
if xlsxFmt.NumFmtID == numFmtId {
|
||||
format := strings.ToLower(xlsxFmt.FormatCode)
|
||||
|
|
10
cell_test.go
10
cell_test.go
|
@ -299,4 +299,14 @@ func TestFormattedValue(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
v = f.formattedValue(1, "43528")
|
||||
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(1, "43528")
|
||||
assert.Equal(t, "43528", v)
|
||||
}
|
||||
|
|
5
sheet.go
5
sheet.go
|
@ -37,8 +37,9 @@ import (
|
|||
// appending the new sheet.
|
||||
func (f *File) NewSheet(name string) int {
|
||||
// Check if the worksheet already exists
|
||||
if f.GetSheetIndex(name) != -1 {
|
||||
return f.SheetCount
|
||||
index := f.GetSheetIndex(name)
|
||||
if index != -1 {
|
||||
return index
|
||||
}
|
||||
f.DeleteSheet(name)
|
||||
f.SheetCount++
|
||||
|
|
|
@ -71,6 +71,8 @@ func TestNewSheet(t *testing.T) {
|
|||
// delete original sheet
|
||||
f.DeleteSheet(f.GetSheetName(f.GetSheetIndex("Sheet1")))
|
||||
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestNewSheet.xlsx")))
|
||||
// create new worksheet with already exists name
|
||||
assert.Equal(t, f.GetSheetIndex("Sheet2"), f.NewSheet("Sheet2"))
|
||||
}
|
||||
|
||||
func TestSetPane(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue