Ver código fonte

Merge pull request #97 from sirwart/numfmt

Fix number formats in workbooks where no custom formats are created
Geoffrey J. Teale 11 anos atrás
pai
commit
41df3b545b
1 arquivos alterados com 5 adições e 4 exclusões
  1. 5 4
      xmlStyle.go

+ 5 - 4
xmlStyle.go

@@ -180,15 +180,16 @@ func getBuiltinNumberFormat(numFmtId int) string {
 }
 
 func (styles *xlsxStyleSheet) getNumberFormat(styleIndex int) string {
-	if styles.CellXfs.Xf == nil || styles.numFmtRefTable == nil {
+	if styles.CellXfs.Xf == nil {
 		return ""
 	}
 	var numberFormat string = ""
 	if styleIndex > -1 && styleIndex <= styles.CellXfs.Count {
 		xf := styles.CellXfs.Xf[styleIndex]
-		if xf.NumFmtId < 164 {
-			return getBuiltinNumberFormat(xf.NumFmtId)
-		} else {
+		if builtin := getBuiltinNumberFormat(xf.NumFmtId); builtin != "" {
+			return builtin
+		}
+		if styles.numFmtRefTable != nil {
 			numFmt := styles.numFmtRefTable[xf.NumFmtId]
 			numberFormat = numFmt.FormatCode
 		}