Browse Source

fix the wrong number of count rest empty rows

nlimpid 8 years ago
parent
commit
a7ea62a41c
3 changed files with 13 additions and 1 deletions
  1. 1 1
      lib.go
  2. 12 0
      lib_test.go
  3. BIN
      testdocs/empty_rows_in_the_rest.xlsx

+ 1 - 1
lib.go

@@ -629,7 +629,7 @@ func readRowsFromSheet(Worksheet *xlsxWorksheet, file *File, sheet *Sheet, rowLi
 	}
 
 	// insert trailing empty rows for the rest of the file
-	for ; insertRowIndex < maxRow; insertRowIndex++ {
+	for ; insertRowIndex < rowCount; insertRowIndex++ {
 		rows[insertRowIndex] = makeEmptyRow(sheet)
 	}
 	return rows, cols, colCount, rowCount

+ 12 - 0
lib_test.go

@@ -1346,3 +1346,15 @@ func (l *LibSuite) TestRoundTripFileWithNoSheetCols(c *C) {
 	c.Assert(err, IsNil)
 	os.Remove("testdocs/after_write.xlsx")
 }
+
+func (l *LibSuite) TestReadRestEmptyRowsFromSheet(c *C) {
+	originalXlFile, err := OpenFile("testdocs/empty_rows_in_the_rest.xlsx")
+	c.Assert(err, IsNil)
+	for _, sheet := range originalXlFile.Sheets {
+		for _, row := range sheet.Rows {
+			if row == nil {
+				c.Errorf("Row should not be nil")
+			}
+		}
+	}
+}

BIN
testdocs/empty_rows_in_the_rest.xlsx