Browse Source

Handle numFmts consistently.

Geoffrey J. Teale 11 years ago
parent
commit
ffa2755661
3 changed files with 13 additions and 3 deletions
  1. 2 1
      file_test.go
  2. 1 1
      lib.go
  3. 10 1
      xmlStyle.go

+ 2 - 1
file_test.go

@@ -140,7 +140,7 @@ func (l *FileSuite) TestReadWorkbookRelationsFromZipFile(c *C) {
 	c.Assert(sheet, NotNil)
 	c.Assert(sheet, NotNil)
 }
 }
 
 
-// +build fudge
+// Style information is correctly extracted from the zipped XLSX file.
 func (l *FileSuite) TestGetStyleFromZipFile(c *C) {
 func (l *FileSuite) TestGetStyleFromZipFile(c *C) {
 	var xlsxFile *File
 	var xlsxFile *File
 	var err error
 	var err error
@@ -771,6 +771,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="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>
       <xf applyAlignment="false" applyBorder="false" applyFont="false" applyFill="false" applyProtection="false" borderId="1" fillId="1" fontId="1" numFmtId="0"></xf>
     </cellXfs>
     </cellXfs>
+    <numFmts count="0"></numFmts>
   </styleSheet>`
   </styleSheet>`
 	c.Assert(parts["xl/styles.xml"], Equals, expectedStyles)
 	c.Assert(parts["xl/styles.xml"], Equals, expectedStyles)
 }
 }

+ 1 - 1
lib.go

@@ -537,7 +537,7 @@ func readStylesFromZipFile(f *zip.File) (*xlsxStyleSheet, error) {
 
 
 func buildNumFmtRefTable(style *xlsxStyleSheet) map[int]xlsxNumFmt {
 func buildNumFmtRefTable(style *xlsxStyleSheet) map[int]xlsxNumFmt {
 	refTable := make(map[int]xlsxNumFmt)
 	refTable := make(map[int]xlsxNumFmt)
-	for _, numFmt := range style.NumFmts {
+	for _, numFmt := range style.NumFmts.NumFmt {
 		refTable[numFmt.NumFmtId] = numFmt
 		refTable[numFmt.NumFmtId] = numFmt
 	}
 	}
 	return refTable
 	return refTable

+ 10 - 1
xmlStyle.go

@@ -25,7 +25,16 @@ type xlsxStyleSheet struct {
 	Borders      xlsxBorders      `xml:"borders,omitempty"`
 	Borders      xlsxBorders      `xml:"borders,omitempty"`
 	CellStyleXfs xlsxCellStyleXfs `xml:"cellStyleXfs,omitempty"`
 	CellStyleXfs xlsxCellStyleXfs `xml:"cellStyleXfs,omitempty"`
 	CellXfs      xlsxCellXfs      `xml:"cellXfs,omitempty"`
 	CellXfs      xlsxCellXfs      `xml:"cellXfs,omitempty"`
-	NumFmts      []xlsxNumFmt     `xml:numFmts>numFmt,omitempty"`
+	NumFmts      xlsxNumFmts      `xml:"numFmts,omitempty"`
+}
+
+// xlsxNumFmts directly maps the numFmts 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 xlsxNumFmts struct {
+	Count  int          `xml:"count,attr"`
+	NumFmt []xlsxNumFmt `xml:"numFmt,omitempty"`
 }
 }
 
 
 // xlsxNumFmt directly maps the numFmt element in the namespace
 // xlsxNumFmt directly maps the numFmt element in the namespace