Browse Source

Rename styles to styleSheet (as per XML).

Geoffrey J. Teale 11 years ago
parent
commit
00d7b43c2d
6 changed files with 25 additions and 22 deletions
  1. 2 2
      file.go
  2. 2 2
      file_test.go
  3. 5 5
      lib.go
  4. 1 1
      sheet.go
  5. 3 3
      sheet_test.go
  6. 12 9
      xmlStyle.go

+ 2 - 2
file.go

@@ -16,7 +16,7 @@ type File struct {
 	numFmtRefTable map[int]xlsxNumFmt
 	referenceTable *RefTable
 	Date1904       bool
-	styles         *xlsxStyles
+	styles         *xlsxStyleSheet
 	Sheets         []*Sheet
 	Sheet          map[string]*Sheet
 }
@@ -144,7 +144,7 @@ func (f *File) MarshallParts() (map[string]string, error) {
 	workbook = f.makeWorkbook()
 	sheetIndex := 1
 
-	styles := &xlsxStyles{}
+	styles := &xlsxStyleSheet{}
 	for _, sheet := range f.Sheets {
 		xSheet := sheet.makeXLSXSheet(refTable, styles)
 		rId := fmt.Sprintf("rId%d", sheetIndex)

+ 2 - 2
file_test.go

@@ -392,7 +392,7 @@ func (l *FileSuite) TestMarshalFile(c *C) {
 	// For now we only allow simple string data in the
 	// spreadsheet.  Style support will follow.
 	expectedStyles := `<?xml version="1.0" encoding="UTF-8"?>
-  <xlsxStyles>
+  <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
     <fonts count="2">
       <font>
         <sz val="12"></sz>
@@ -443,7 +443,7 @@ func (l *FileSuite) TestMarshalFile(c *C) {
       <xf applyAlignment="false" applyBorder="false" applyFont="false" applyFill="false" applyProtection="false" borderId="0" fillId="0" fontId="0" numFmtId="0"></xf>
       <xf applyAlignment="false" applyBorder="false" applyFont="false" applyFill="false" applyProtection="false" borderId="1" fillId="1" fontId="1" numFmtId="0"></xf>
     </cellXfs>
-  </xlsxStyles>`
+  </styleSheet>`
 	c.Assert(parts["xl/styles.xml"], Equals, expectedStyles)
 }
 

+ 5 - 5
lib.go

@@ -509,8 +509,8 @@ func readSharedStringsFromZipFile(f *zip.File) (*RefTable, error) {
 // readStylesFromZipFile() is an internal helper function to
 // extract a style table from the style.xml file within
 // the XLSX zip file.
-func readStylesFromZipFile(f *zip.File) (*xlsxStyles, error) {
-	var style *xlsxStyles
+func readStylesFromZipFile(f *zip.File) (*xlsxStyleSheet, error) {
+	var style *xlsxStyleSheet
 	var error error
 	var rc io.ReadCloser
 	var decoder *xml.Decoder
@@ -518,7 +518,7 @@ func readStylesFromZipFile(f *zip.File) (*xlsxStyles, error) {
 	if error != nil {
 		return nil, error
 	}
-	style = new(xlsxStyles)
+	style = new(xlsxStyleSheet)
 	decoder = xml.NewDecoder(rc)
 	error = decoder.Decode(style)
 	if error != nil {
@@ -527,7 +527,7 @@ func readStylesFromZipFile(f *zip.File) (*xlsxStyles, error) {
 	return style, nil
 }
 
-func buildNumFmtRefTable(style *xlsxStyles) map[int]xlsxNumFmt {
+func buildNumFmtRefTable(style *xlsxStyleSheet) map[int]xlsxNumFmt {
 	refTable := make(map[int]xlsxNumFmt)
 	for _, numFmt := range style.NumFmts {
 		refTable[numFmt.NumFmtId] = numFmt
@@ -618,7 +618,7 @@ func ReadZipReader(r *zip.Reader) (*File, error) {
 	var sheetXMLMap map[string]string
 	var sheetsByName map[string]*Sheet
 	var sheets []*Sheet
-	var style *xlsxStyles
+	var style *xlsxStyleSheet
 	var styles *zip.File
 	var v *zip.File
 	var workbook *zip.File

+ 1 - 1
sheet.go

@@ -42,7 +42,7 @@ func (sh *Sheet) Cell(row, col int) *Cell {
 }
 
 // Dump sheet to it's XML representation, intended for internal use only
-func (s *Sheet) makeXLSXSheet(refTable *RefTable, styles *xlsxStyles) *xlsxWorksheet {
+func (s *Sheet) makeXLSXSheet(refTable *RefTable, styles *xlsxStyleSheet) *xlsxWorksheet {
 	worksheet := &xlsxWorksheet{}
 	xSheet := xlsxSheetData{}
 	maxRow := 0

+ 3 - 3
sheet_test.go

@@ -28,7 +28,7 @@ func (s *SheetSuite) TestMakeXLSXSheetFromRows(c *C) {
 	cell := row.AddCell()
 	cell.Value = "A cell!"
 	refTable := NewSharedStringRefTable()
-	styles := &xlsxStyles{}
+	styles := &xlsxStyleSheet{}
 	xSheet := sheet.makeXLSXSheet(refTable, styles)
 	c.Assert(xSheet.Dimension.Ref, Equals, "A1:A1")
 	c.Assert(xSheet.SheetData.Row, HasLen, 1)
@@ -74,7 +74,7 @@ func (s *SheetSuite) TestMakeXLSXSheetAlsoPopulatesXLSXSTyles(c *C) {
 	cell2.SetStyle(style2)
 
 	refTable := NewSharedStringRefTable()
-	styles := &xlsxStyles{}
+	styles := &xlsxStyleSheet{}
 	worksheet := sheet.makeXLSXSheet(refTable, styles)
 
 	c.Assert(styles.Fonts.Count, Equals, 2)
@@ -125,7 +125,7 @@ func (s *SheetSuite) TestMarshalSheet(c *C) {
 	cell := row.AddCell()
 	cell.Value = "A cell!"
 	refTable := NewSharedStringRefTable()
-	styles := &xlsxStyles{}
+	styles := &xlsxStyleSheet{}
 	xSheet := sheet.makeXLSXSheet(refTable, styles)
 
 	output := bytes.NewBufferString(xml.Header)

+ 12 - 9
xmlStyle.go

@@ -8,15 +8,18 @@
 package xlsx
 
 import (
+	"encoding/xml"
 	"strconv"
 	"strings"
 )
 
-// xlsxStyle directly maps the style element in the namespace
+// xlsxStyle directly maps the styleSheet element in the namespace
 // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
 // currently I have not checked it for completeness - it does as much
 // as I need.
-type xlsxStyles struct {
+type xlsxStyleSheet struct {
+	XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main styleSheet"`
+
 	Fonts        xlsxFonts        `xml:"fonts,omitempty"`
 	Fills        xlsxFills        `xml:"fills,omitempty"`
 	Borders      xlsxBorders      `xml:"borders,omitempty"`
@@ -170,7 +173,7 @@ type xlsxAlignment struct {
 	WrapText     bool   `xml:"wrapText,attr"`
 }
 
-func (styles *xlsxStyles) getStyle(styleIndex int) (style Style) {
+func (styles *xlsxStyleSheet) getStyle(styleIndex int) (style Style) {
 	var styleXf xlsxXf
 	style = Style{}
 	style.Border = Border{}
@@ -219,7 +222,7 @@ func (styles *xlsxStyles) getStyle(styleIndex int) (style Style) {
 
 }
 
-func (styles *xlsxStyles) getNumberFormat(styleIndex int, numFmtRefTable map[int]xlsxNumFmt) string {
+func (styles *xlsxStyleSheet) getNumberFormat(styleIndex int, numFmtRefTable map[int]xlsxNumFmt) string {
 	if styles.CellXfs.Xf == nil {
 		return ""
 	}
@@ -232,35 +235,35 @@ func (styles *xlsxStyles) getNumberFormat(styleIndex int, numFmtRefTable map[int
 	return strings.ToLower(numberFormat)
 }
 
-func (styles *xlsxStyles) addFont(xFont xlsxFont) (index int) {
+func (styles *xlsxStyleSheet) addFont(xFont xlsxFont) (index int) {
 	styles.Fonts.Font = append(styles.Fonts.Font, xFont)
 	index = styles.Fonts.Count
 	styles.Fonts.Count += 1
 	return
 }
 
-func (styles *xlsxStyles) addFill(xFill xlsxFill) (index int) {
+func (styles *xlsxStyleSheet) addFill(xFill xlsxFill) (index int) {
 	styles.Fills.Fill = append(styles.Fills.Fill, xFill)
 	index = styles.Fills.Count
 	styles.Fills.Count += 1
 	return
 }
 
-func (styles *xlsxStyles) addBorder(xBorder xlsxBorder) (index int) {
+func (styles *xlsxStyleSheet) addBorder(xBorder xlsxBorder) (index int) {
 	styles.Borders.Border = append(styles.Borders.Border, xBorder)
 	index = styles.Borders.Count
 	styles.Borders.Count += 1
 	return
 }
 
-func (styles *xlsxStyles) addCellStyleXf(xCellStyleXf xlsxXf) (index int) {
+func (styles *xlsxStyleSheet) addCellStyleXf(xCellStyleXf xlsxXf) (index int) {
 	styles.CellStyleXfs.Xf = append(styles.CellStyleXfs.Xf, xCellStyleXf)
 	index = styles.CellStyleXfs.Count
 	styles.CellStyleXfs.Count += 1
 	return
 }
 
-func (styles *xlsxStyles) addCellXf(xCellXf xlsxXf) (index int) {
+func (styles *xlsxStyleSheet) addCellXf(xCellXf xlsxXf) (index int) {
 	styles.CellXfs.Xf = append(styles.CellXfs.Xf, xCellXf)
 	index = styles.CellXfs.Count
 	styles.CellXfs.Count += 1