Browse Source

* Change Style.Fills -> Style.Fill (a better name for a singular element)
* Add test for Fills getting copied into user facing Style struct.

Geoffrey J. Teale 12 years ago
parent
commit
0e341d43a5
3 changed files with 40 additions and 5 deletions
  1. 2 2
      lib.go
  2. 36 0
      lib_test.go
  3. 2 3
      worksheet.go

+ 2 - 2
lib.go

@@ -58,7 +58,7 @@ func (c *Cell) GetStyle() *Style {
 			fill.PatternType = c.styles.Fills[xf.FillId].PatternFill.PatternType
 			fill.BgColor = c.styles.Fills[xf.FillId].PatternFill.BgColor.RGB
 			fill.FgColor = c.styles.Fills[xf.FillId].PatternFill.FgColor.RGB
-			style.Fills = fill
+			style.Fill = fill
 		}
 		if xf.ApplyFont {
 			font := c.styles.Fonts[xf.FontId]
@@ -90,7 +90,7 @@ type Sheet struct {
 // the contents of Style within an XLSX file.
 type Style struct {
 	Boders Border
-	Fills  Fill
+	Fill   Fill
 	Font   Font
 }
 

+ 36 - 0
lib_test.go

@@ -97,6 +97,42 @@ func TestGetStyleWithFonts(t *testing.T) {
 	}
 }
 
+// Test that GetStyle correctly converts the xlsxStyle.Fills.
+func TestGetStyleWithFills(t *testing.T) {
+	var cell *Cell
+	var style *Style
+	var xStyles *xlsxStyles
+	var fills []xlsxFill
+	var cellXfs []xlsxXf
+
+	fills = make([]xlsxFill, 1)
+	fills[0] = xlsxFill{
+		PatternFill: xlsxPatternFill{
+			PatternType: "solid",
+			FgColor:     xlsxColor{RGB: "FF000000"},
+			BgColor:     xlsxColor{RGB: "00FF0000"}}}
+	cellXfs = make([]xlsxXf, 1)
+	cellXfs[0] = xlsxXf{ApplyFill: true, FillId: 0}
+
+	xStyles = &xlsxStyles{Fills: fills, CellXfs: cellXfs}
+
+	cell = &Cell{Value: "123", styleIndex: 1, styles: xStyles}
+	style = cell.GetStyle()
+	fill := style.Fill
+	if fill.PatternType != "solid" {
+		t.Error("Expected fill.PatternType == 'solid', but got ",
+			fill.PatternType)
+	}
+	if fill.BgColor != "00FF0000" {
+		t.Error("Expected fill.BgColor == '00FF0000', but got ",
+			fill.BgColor)
+	}
+	if fill.FgColor != "FF000000" {
+		t.Error("Expected fill.FgColor == 'FF000000', but got ",
+			fill.FgColor)
+	}
+}
+
 // Test that we can correctly extract a reference table from the
 // sharedStrings.xml file embedded in the XLSX file and return a
 // reference table of string values from it.

+ 2 - 3
worksheet.go

@@ -5,8 +5,8 @@ package xlsx
 // currently I have not checked it for completeness - it does as much
 // as I need.
 type xlsxWorksheet struct {
-	Dimension     xlsxDimension          `xml:"dimension"`
-	SheetData     xlsxSheetData     `xml:"sheetData"`
+	Dimension xlsxDimension `xml:"dimension"`
+	SheetData xlsxSheetData `xml:"sheetData"`
 }
 
 // xlsxDimension directly maps the dimension element in the namespace
@@ -17,7 +17,6 @@ type xlsxDimension struct {
 	Ref string `xml:"ref,attr"`
 }
 
-
 // xlsxSheetData directly maps the sheetData element in the namespace
 // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
 // currently I have not checked it for completeness - it does as much