Browse Source

Set CellStyleXf FontId, FillId and BorderId.

Geoffrey J. Teale 11 years ago
parent
commit
e783c6e8d9
3 changed files with 16 additions and 7 deletions
  1. 6 3
      sheet.go
  2. 4 1
      sheet_test.go
  3. 6 3
      xmlStyle.go

+ 6 - 3
sheet.go

@@ -56,9 +56,12 @@ func (s *Sheet) makeXLSXSheet(refTable *RefTable, styles *xlsxStyles) *xlsxWorks
 		for c, cell := range row.Cells {
 			style := cell.GetStyle()
 			xFont, xFill, xBorder, xCellStyleXf, xCellXf := style.makeXLSXStyleElements()
-			styles.addFont(xFont)
-			styles.addFill(xFill)
-			styles.addBorder(xBorder)
+			fontId := styles.addFont(xFont)
+			fillId := styles.addFill(xFill)
+			borderId := styles.addBorder(xBorder)
+			xCellStyleXf.FontId = fontId
+			xCellStyleXf.FillId = fillId
+			xCellStyleXf.BorderId = borderId
 			styles.addCellStyleXf(xCellStyleXf)
 			styles.addCellXf(xCellXf)
 			if c > maxCell {

+ 4 - 1
sheet_test.go

@@ -66,7 +66,6 @@ func (s *SheetSuite) TestMakeXLSXSheetAlsoPopulatesXLSXSTyles(c *C) {
 	styles := &xlsxStyles{}
 	_ = sheet.makeXLSXSheet(refTable, styles)
 	c.Assert(len(styles.Fonts), Equals, 1)
-	// YOU ARE HERE
 	c.Assert(styles.Fonts[0].Sz.Val, Equals, "10")
 	c.Assert(styles.Fonts[0].Name.Val, Equals, "Verdana")
 	c.Assert(len(styles.Fills), Equals, 1)
@@ -78,6 +77,10 @@ func (s *SheetSuite) TestMakeXLSXSheetAlsoPopulatesXLSXSTyles(c *C) {
 	c.Assert(styles.Borders[0].Right.Style, Equals, "thin")
 	c.Assert(styles.Borders[0].Top.Style, Equals, "none")
 	c.Assert(styles.Borders[0].Bottom.Style, Equals, "thin")
+	c.Assert(len(styles.CellStyleXfs), Equals, 1)
+	c.Assert(styles.CellStyleXfs[0].FontId, Equals, 0)
+	c.Assert(styles.CellStyleXfs[0].FillId, Equals, 0)
+	c.Assert(styles.CellStyleXfs[0].BorderId, Equals, 0)
 }
 
 func (s *SheetSuite) TestMarshalSheet(c *C) {

+ 6 - 3
xmlStyle.go

@@ -179,16 +179,19 @@ func (styles *xlsxStyles) getNumberFormat(styleIndex int, numFmtRefTable map[int
 	return strings.ToLower(numberFormat)
 }
 
-func (styles *xlsxStyles) addFont(xFont xlsxFont) {
+func (styles *xlsxStyles) addFont(xFont xlsxFont) int {
 	styles.Fonts = append(styles.Fonts, xFont)
+	return len(styles.Fonts) - 1
 }
 
-func (styles *xlsxStyles) addFill(xFill xlsxFill) {
+func (styles *xlsxStyles) addFill(xFill xlsxFill) int {
 	styles.Fills = append(styles.Fills, xFill)
+	return len(styles.Fills) - 1
 }
 
-func (styles *xlsxStyles) addBorder(xBorder xlsxBorder) {
+func (styles *xlsxStyles) addBorder(xBorder xlsxBorder) int {
 	styles.Borders = append(styles.Borders, xBorder)
+	return len(styles.Borders) - 1
 }
 
 func (styles *xlsxStyles) addCellStyleXf(xCellStyleXf xlsxXf) {