Browse Source

Use zero index for <col> min and max.

Geoffrey J. Teale 11 years ago
parent
commit
60ffcaa279
4 changed files with 5 additions and 5 deletions
  1. 1 1
      file_test.go
  2. 2 2
      lib.go
  3. 1 1
      sheet.go
  4. 1 1
      sheet_test.go

+ 1 - 1
file_test.go

@@ -285,7 +285,7 @@ func (l *FileSuite) TestMarshalFile(c *C) {
   <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
     <dimension ref="A1:A1"></dimension>
     <cols>
-      <col min="1" max="1"></col>
+      <col min="0" max="0"></col>
     </cols>
     <sheetData>
       <row r="1">

+ 2 - 2
lib.go

@@ -365,8 +365,8 @@ func readRowsFromSheet(Worksheet *xlsxWorksheet, file *File) ([]*Row, []*Col, in
 		// exist outside the defined dimensions of the
 		// spreadsheet - we deliberately exclude these
 		// columns.
-		for i := rawcol.Min; i <= rawcol.Max && i <= colCount; i++ {
-			cols[i-1] = &Col{
+		for i := rawcol.Min; i <= rawcol.Max && i < colCount; i++ {
+			cols[i] = &Col{
 				Min:    rawcol.Min,
 				Max:    rawcol.Max,
 				Hidden: rawcol.Hidden}

+ 1 - 1
sheet.go

@@ -28,7 +28,7 @@ func (s *Sheet) AddRow() *Row {
 // Make sure we always have as many Cols as we do cells.
 func (s *Sheet) maybeAddCol(cellCount int) {
 	if cellCount > s.MaxCol {
-		s.Cols = append(s.Cols, &Col{Min: cellCount, Max: cellCount, Hidden: false})
+		s.Cols = append(s.Cols, &Col{Min: cellCount - 1, Max: cellCount - 1, Hidden: false})
 		s.MaxCol = cellCount
 	}
 }

+ 1 - 1
sheet_test.go

@@ -67,7 +67,7 @@ func (s *SheetSuite) TestMarshalSheet(c *C) {
   <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
     <dimension ref="A1:A1"></dimension>
     <cols>
-      <col min="1" max="1"></col>
+      <col min="0" max="0"></col>
     </cols>
     <sheetData>
       <row r="1">