Browse Source

update tests, initialize cols array

Andrew Schwartz 11 years ago
parent
commit
dc38e85dfc
4 changed files with 9 additions and 2 deletions
  1. 2 1
      file_test.go
  2. 5 0
      lib.go
  3. 1 0
      sheet_test.go
  4. 1 1
      worksheet.go

+ 2 - 1
file_test.go

@@ -2,8 +2,8 @@ package xlsx
 
 import (
 	"encoding/xml"
-	. "gopkg.in/check.v1"
 	"path/filepath"
+	. "gopkg.in/check.v1"
 )
 
 type FileSuite struct{}
@@ -283,6 +283,7 @@ func (l *FileSuite) TestMarshalFile(c *C) {
 	expectedSheet := `<?xml version="1.0" encoding="UTF-8"?>
   <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
     <dimension ref="A1:A1"></dimension>
+    <cols></cols>
     <sheetData>
       <row r="1">
         <c r="A1" t="s">

+ 5 - 0
lib.go

@@ -358,6 +358,11 @@ func readRowsFromSheet(Worksheet *xlsxWorksheet, file *File) ([]*Row, int, int)
 	rows = make([]*Row, rowCount)
 	cols = make([]*Col, colCount)
 	insertRowIndex = minRow
+	for i := range cols {
+		cols[i] = &Col{
+			Hidden: false,
+		}
+	}
 	for colIndex := 0; colIndex < len(Worksheet.Cols.Col); colIndex++ {
 		rawcol := Worksheet.Cols.Col[colIndex]
 		for c := rawcol.Min - 1; c < colCount && c < rawcol.Max; c++ {

+ 1 - 0
sheet_test.go

@@ -65,6 +65,7 @@ func (s *SheetSuite) TestMarshalSheet(c *C) {
 	expectedXLSXSheet := `<?xml version="1.0" encoding="UTF-8"?>
   <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
     <dimension ref="A1:A1"></dimension>
+    <cols></cols>
     <sheetData>
       <row r="1">
         <c r="A1" t="s">

+ 1 - 1
worksheet.go

@@ -11,7 +11,7 @@ import (
 type xlsxWorksheet struct {
 	XMLName   xml.Name      `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main worksheet"`
 	Dimension xlsxDimension `xml:"dimension"`
-	Cols      xslxCols      `xml:"cols"`
+	Cols      xslxCols      `xml:"cols,omitempty"`
 	SheetData xlsxSheetData `xml:"sheetData"`
 }