@@ -37,9 +37,14 @@ class SpreadsheetReader_XLS implements Iterator, Countable
37
37
private $ CurrentRow = array ();
38
38
39
39
/**
40
- * @var int Column count in the file
40
+ * @var int Column count in the sheet
41
41
*/
42
42
private $ ColumnCount = 0 ;
43
+ /**
44
+ * @var int Row count in the sheet
45
+ */
46
+ private $ RowCount = 0 ;
47
+
43
48
/**
44
49
* @var array Template to use for empty rows. Retrieved rows are merged
45
50
* with this so that empty cells are added, too
@@ -119,6 +124,15 @@ public function ChangeSheet($Index)
119
124
$ this -> CurrentSheet = $ Index ;
120
125
121
126
$ this -> ColumnCount = $ this -> Handle -> sheets [$ this -> CurrentSheet ]['numCols ' ];
127
+ $ this -> RowCount = $ this -> Handle -> sheets [$ this -> CurrentSheet ]['numRows ' ];
128
+
129
+ // For the case when Spreadsheet_Excel_Reader doesn't have the row count set correctly.
130
+ if (!$ this -> RowCount && count ($ this -> Handle -> sheets [$ this -> CurrentSheet ]['cells ' ]))
131
+ {
132
+ end ($ this -> Handle -> sheets [$ this -> CurrentSheet ]['cells ' ]);
133
+ $ this -> RowCount = (int )key ($ this -> Handle -> sheets [$ this -> CurrentSheet ]['cells ' ]);
134
+ }
135
+
122
136
$ this -> EmptyRow = array_fill (1 , $ this -> ColumnCount , '' );
123
137
}
124
138
@@ -221,7 +235,7 @@ public function valid()
221
235
{
222
236
return false ;
223
237
}
224
- return ($ this -> Index <= $ this -> Handle -> sheets [ $ this -> CurrentSheet ][ ' numRows ' ] );
238
+ return ($ this -> Index <= $ this -> RowCount );
225
239
}
226
240
227
241
// !Countable interface method
@@ -236,7 +250,7 @@ public function count()
236
250
return 0 ;
237
251
}
238
252
239
- return $ this -> Handle -> sheets [ $ this -> CurrentSheet ][ ' numRows ' ] ;
253
+ return $ this -> RowCount ;
240
254
}
241
255
}
242
256
?>
0 commit comments