I have experienced a problem with loading a CSV file into an array when using the PHPExcel_Worksheet::toArray method. The "empty cells" were skipped, and as the array is numerical, this caused problems whit interpretation of the data. BTW: the
same happens when the "cell" only containes a space.
Example CSV file (cell C2 is empty):
$reader = new PHPExcel_Reader_CSV();
$e = $reader->load($f['tmp_name']);
$sheet = $e->getSheet(0);
$data = $sheet->toArray("",false,false);
$data = Array(
0 => Array(
0 => 'A',
1 => 'B',
2 => 'C',
3 => 'D'
1 => Array(
0 => 1,
1 => 2,
2 => 4
I've tried to fix this with setting the delimiter, different encodings or the enclosure (which isn't there), but nothing made a difference. Ultimately I've decided to read the data by using the iterator methods, which worked, but that's a lot more to code...
I do not have this problem with xls or xlsx files with empty cells.
Have other also experienced this problem?
Feb 9, 2011 at 9:26 PM
This problem has been resolved in the latest SVN code.
0 => <small>string</small> 'A' (length=1)
1 => <small>string</small> 'B' (length=1)
2 => <small>string</small> 'C' (length=1)
3 => <small>string</small> 'D' (length=1)
0 => <small>float</small> 1
1 => <small>float</small> 2
2 => <small>string</small> '' (length=0)
3 => <small>float</small> 4