Excel5 read columns and rows

Feb 17, 2009 at 1:18 PM
Edited Feb 18, 2009 at 7:35 AM
Hello,

Maybe somebody could help me.
########################################################################
My script works fine:
include 'PHPExcel.php';
include 'PHPExcel/IOFactory.php';

$objReader = PHPExcel_IOFactory::createReader('Excel5');
$PHPExcel = $objReader->load('file.xls');
$sheet = $PHPExcel->getActiveSheet();

foreach($PHPExcel->getActiveSheet()->getRowDimensions() as $rows)
{    
    foreach($PHPExcel->getActiveSheet()->getColumnDimensions() as $col)
    {
    $value = $sheet->getCell($col->getColumnIndex().$rows->getRowIndex())->getValue();
    echo $value."\t";
    }
echo "<br />";
}
########################################################################
but when I change file location, like this:
$PHPExcel = $objReader->load('c:/file.xls');
it dosn't read the file, but the file exist...

Please somebody give me solution
The file location is important because I will make file upload.

 
Developer
Feb 17, 2009 at 6:00 PM
Are you getting any error messages? If not, put this at the beginning of your script:

error_reporting(E_ALL);
ini_set('display_errors', '1');

Feb 18, 2009 at 8:09 AM
Edited Feb 18, 2009 at 9:30 AM
OK the problem is resolved. There was some config problems with server. And I update the previous script because I forgot this row $sheet = $PHPExcel->getActiveSheet();

But there is still one problem. When I create new xls or xlsx file and put there rows for example:
AAAA      BBBB       CCCC
1111         2222         5555

the script doesn't read them while I don't set text align for columns. The script return nothing like file is empty and don't get any error messages too anyway I am using:
 error_reporting(E_ALL);
ini_set('display_errors', '1');


How it is possible that sheets became active when I just put some text?

Thank koyama for message it help resolve the previous problem.
Developer
Feb 18, 2009 at 11:35 PM
I think this has to do with how you are looping through the cells. You can find example of correct method for doing this:
http://www.codeplex.com/PHPExcel/WorkItem/View.aspx?WorkItemId=8931

There will be some enhancements in PHPExcel 1.6.6, but for now you can use the technique shown in the example.