Procházet zdrojové kódy

update tests, initialize cols array

Andrew Schwartz před 11 roky
rodič
revize
dc38e85dfc
4 změnil soubory, kde provedl 9 přidání a 2 odebrání
  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 (
 import (
 	"encoding/xml"
 	"encoding/xml"
-	. "gopkg.in/check.v1"
 	"path/filepath"
 	"path/filepath"
+	. "gopkg.in/check.v1"
 )
 )
 
 
 type FileSuite struct{}
 type FileSuite struct{}
@@ -283,6 +283,7 @@ func (l *FileSuite) TestMarshalFile(c *C) {
 	expectedSheet := `<?xml version="1.0" encoding="UTF-8"?>
 	expectedSheet := `<?xml version="1.0" encoding="UTF-8"?>
   <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
   <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
     <dimension ref="A1:A1"></dimension>
     <dimension ref="A1:A1"></dimension>
+    <cols></cols>
     <sheetData>
     <sheetData>
       <row r="1">
       <row r="1">
         <c r="A1" t="s">
         <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)
 	rows = make([]*Row, rowCount)
 	cols = make([]*Col, colCount)
 	cols = make([]*Col, colCount)
 	insertRowIndex = minRow
 	insertRowIndex = minRow
+	for i := range cols {
+		cols[i] = &Col{
+			Hidden: false,
+		}
+	}
 	for colIndex := 0; colIndex < len(Worksheet.Cols.Col); colIndex++ {
 	for colIndex := 0; colIndex < len(Worksheet.Cols.Col); colIndex++ {
 		rawcol := Worksheet.Cols.Col[colIndex]
 		rawcol := Worksheet.Cols.Col[colIndex]
 		for c := rawcol.Min - 1; c < colCount && c < rawcol.Max; c++ {
 		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"?>
 	expectedXLSXSheet := `<?xml version="1.0" encoding="UTF-8"?>
   <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
   <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
     <dimension ref="A1:A1"></dimension>
     <dimension ref="A1:A1"></dimension>
+    <cols></cols>
     <sheetData>
     <sheetData>
       <row r="1">
       <row r="1">
         <c r="A1" t="s">
         <c r="A1" t="s">

+ 1 - 1
worksheet.go

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