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.
|
// setCustomNumFmt provides a function to set custom number format code.
|
||||||
func setCustomNumFmt(styleSheet *xlsxStyleSheet, style *Style) int {
|
func setCustomNumFmt(styleSheet *xlsxStyleSheet, style *Style) int {
|
||||||
nf := xlsxNumFmt{FormatCode: *style.CustomNumFmt}
|
nf := xlsxNumFmt{NumFmtID: 163, FormatCode: *style.CustomNumFmt}
|
||||||
|
if styleSheet.NumFmts == nil {
|
||||||
if styleSheet.NumFmts != nil {
|
styleSheet.NumFmts = &xlsxNumFmts{}
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
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
|
return nf.NumFmtID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -296,7 +296,7 @@ type xlsxNumFmts struct {
|
||||||
// of a cell.
|
// of a cell.
|
||||||
type xlsxNumFmt struct {
|
type xlsxNumFmt struct {
|
||||||
NumFmtID int `xml:"numFmtId,attr"`
|
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"`
|
FormatCode16 string `xml:"http://schemas.microsoft.com/office/spreadsheetml/2015/02/main formatCode16,attr,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue