This closes #1677, fix the incorrect custom number format ID allocated
- Improve compatibility with empty custom number format code
This commit is contained in:
parent
f85770f4c9
commit
1c7c417c70
24
styles.go
24
styles.go
|
@ -1694,20 +1694,18 @@ func newNumFmt(styleSheet *xlsxStyleSheet, style *Style) int {
|
|||
|
||||
// setCustomNumFmt provides a function to set custom number format code.
|
||||
func setCustomNumFmt(styleSheet *xlsxStyleSheet, style *Style) int {
|
||||
nf := xlsxNumFmt{FormatCode: *style.CustomNumFmt}
|
||||
|
||||
if styleSheet.NumFmts != nil {
|
||||
nf.NumFmtID = styleSheet.NumFmts.NumFmt[len(styleSheet.NumFmts.NumFmt)-1].NumFmtID + 1
|
||||
styleSheet.NumFmts.NumFmt = append(styleSheet.NumFmts.NumFmt, &nf)
|
||||
styleSheet.NumFmts.Count++
|
||||
} else {
|
||||
nf.NumFmtID = 164
|
||||
numFmts := xlsxNumFmts{
|
||||
NumFmt: []*xlsxNumFmt{&nf},
|
||||
Count: 1,
|
||||
}
|
||||
styleSheet.NumFmts = &numFmts
|
||||
nf := xlsxNumFmt{NumFmtID: 163, FormatCode: *style.CustomNumFmt}
|
||||
if styleSheet.NumFmts == nil {
|
||||
styleSheet.NumFmts = &xlsxNumFmts{}
|
||||
}
|
||||
for _, numFmt := range styleSheet.NumFmts.NumFmt {
|
||||
if numFmt != nil && nf.NumFmtID < numFmt.NumFmtID {
|
||||
nf.NumFmtID = numFmt.NumFmtID
|
||||
}
|
||||
}
|
||||
nf.NumFmtID++
|
||||
styleSheet.NumFmts.NumFmt = append(styleSheet.NumFmts.NumFmt, &nf)
|
||||
styleSheet.NumFmts.Count = len(styleSheet.NumFmts.NumFmt)
|
||||
return nf.NumFmtID
|
||||
}
|
||||
|
||||
|
|
|
@ -296,7 +296,7 @@ type xlsxNumFmts struct {
|
|||
// of a cell.
|
||||
type xlsxNumFmt struct {
|
||||
NumFmtID int `xml:"numFmtId,attr"`
|
||||
FormatCode string `xml:"formatCode,attr,omitempty"`
|
||||
FormatCode string `xml:"formatCode,attr"`
|
||||
FormatCode16 string `xml:"http://schemas.microsoft.com/office/spreadsheetml/2015/02/main formatCode16,attr,omitempty"`
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue