Skip to content

Commit bb7c29a

Browse files
committed
Merge pull request nuovo#36 from pilsetnieks/master
Bugfix for when the row count cannot be read from XLS file
2 parents a9cc2cd + bb9c93b commit bb7c29a

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### v.0.5.2 2013-06-28
2+
3+
- A fix for the case when row count wasn't read correctly from the sheet in a XLS file.
4+
15
### v.0.5.1 2013-06-27
26

37
- Fixed file type choice when using mime-types (previously there were problems with

SpreadsheetReader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Main class for spreadsheet reading
44
*
5-
* @version 0.5.1
5+
* @version 0.5.2
66
* @author Martins Pilsetnieks
77
*/
88
class SpreadsheetReader implements Iterator, Countable

SpreadsheetReader_XLS.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,14 @@ class SpreadsheetReader_XLS implements Iterator, Countable
3737
private $CurrentRow = array();
3838

3939
/**
40-
* @var int Column count in the file
40+
* @var int Column count in the sheet
4141
*/
4242
private $ColumnCount = 0;
43+
/**
44+
* @var int Row count in the sheet
45+
*/
46+
private $RowCount = 0;
47+
4348
/**
4449
* @var array Template to use for empty rows. Retrieved rows are merged
4550
* with this so that empty cells are added, too
@@ -119,6 +124,15 @@ public function ChangeSheet($Index)
119124
$this -> CurrentSheet = $Index;
120125

121126
$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+
122136
$this -> EmptyRow = array_fill(1, $this -> ColumnCount, '');
123137
}
124138

@@ -221,7 +235,7 @@ public function valid()
221235
{
222236
return false;
223237
}
224-
return ($this -> Index <= $this -> Handle -> sheets[$this -> CurrentSheet]['numRows']);
238+
return ($this -> Index <= $this -> RowCount);
225239
}
226240

227241
// !Countable interface method
@@ -236,7 +250,7 @@ public function count()
236250
return 0;
237251
}
238252

239-
return $this -> Handle -> sheets[$this -> CurrentSheet]['numRows'];
253+
return $this -> RowCount;
240254
}
241255
}
242256
?>

0 commit comments

Comments
 (0)