Jelajahi Sumber

value fields xlsxPatternFill.FgColor & xlsxPatternFill.BgColor cause … (#770)

* value fields xlsxPatternFill.FgColor & xlsxPatternFill.BgColor cause ineffective omitempty tags

* remove useless omitempty tag on xlsxPatternFill.FgColor and xlsxPatternFill.BgColor
Eagle Xiang 4 tahun lalu
induk
melakukan
219add2f0e
2 mengubah file dengan 9 tambahan dan 3 penghapusan
  1. 6 0
      styles.go
  2. 3 3
      xmlStyles.go

+ 6 - 0
styles.go

@@ -2432,8 +2432,14 @@ func newFills(style *Style, fg bool) *xlsxFill {
 		var pattern xlsxPatternFill
 		pattern.PatternType = patterns[style.Fill.Pattern]
 		if fg {
+			if pattern.FgColor == nil {
+				pattern.FgColor = new(xlsxColor)
+			}
 			pattern.FgColor.RGB = getPaletteColor(style.Fill.Color[0])
 		} else {
+			if pattern.BgColor == nil {
+				pattern.BgColor = new(xlsxColor)
+			}
 			pattern.BgColor.RGB = getPaletteColor(style.Fill.Color[0])
 		}
 		fill.PatternFill = &pattern

+ 3 - 3
xmlStyles.go

@@ -120,9 +120,9 @@ type xlsxFill struct {
 // For cell fills with patterns specified, then the cell fill color is
 // specified by the bgColor element.
 type xlsxPatternFill struct {
-	PatternType string    `xml:"patternType,attr,omitempty"`
-	FgColor     xlsxColor `xml:"fgColor,omitempty"`
-	BgColor     xlsxColor `xml:"bgColor,omitempty"`
+	PatternType string     `xml:"patternType,attr,omitempty"`
+	FgColor     *xlsxColor `xml:"fgColor"`
+	BgColor     *xlsxColor `xml:"bgColor"`
 }
 
 // xlsxGradientFill defines a gradient-style cell fill. Gradient cell fills can