Fatal error: Uncaught exception 'PHPExcel_Exception'

Topics: Developer Forum
Feb 19, 2013 at 8:35 AM
Edited Feb 19, 2013 at 8:43 AM
hello everyone, when i run my php script to transform xlsx file to csv file, i get an error like this:
Fatal error: Uncaught exception 'PHPExcel_Exception' with message 'Sheet1!E2 ->
Invalid cell coordinate A' in C:\xampp-portable\htdocs\xlsx2csv\Classes\PHPExcel
\Cell.php on line 307

PHPExcel_Exception: Sheet1!E2 -> Invalid cell coordinate A in C:\xampp-portable\
htdocs\xlsx2csv\Classes\PHPExcel\Cell.php on line 307

Call Stack:
    0.0010     131784   1. {main}() C:\xampp-portable\htdocs\xlsx2csv\Tests\test
.php:0
    3.7742    3295200   2. PHPExcel_Writer_CSV->save(string(38)) C:\xampp-portab
le\htdocs\xlsx2csv\Tests\test.php:66
    3.8375    3314104   3. PHPExcel_Worksheet->rangeToArray(string(5), string(0)
, bool, ???, ???) C:\xampp-portable\htdocs\xlsx2csv\Classes\PHPExcel\Writer\CSV.
php:140
    3.8572    3315336   4. PHPExcel_Cell->getCalculatedValue(???) C:\xampp-porta
ble\htdocs\xlsx2csv\Classes\PHPExcel\Worksheet.php:2415
file used: 123.xlsx

the PHPExcel version i'm using: 1.7.8

do anyone know how to solve it?
my code as follows:
$baseDir = $argv[1];
$outDir = $argv[2];

if(!file_exists($baseDir)){
    echo $baseDir . " (the directory doesn't exist!)";
}else{
    if(is_dir($baseDir) && $list = opendir($baseDir)){
        while($filename = readdir($list)){
            $fullName = $baseDir . DIRECTORY_SEPARATOR . $filename;
            if(is_file($fullName)){
                $fileType = substr(strrchr($filename, '.'),1);
                if($fileType == "xlsx" || $fileType == "xls"){
                    echo "processing: " . $filename . " ..\n";
                    if($fileType == "xlsx")
                        $objReader = new PHPExcel_Reader_Excel2007();
                    else
                        $objReader = new PHPExcel_Reader_Excel5();
                    $objReader->setReadDataOnly(true);
                    $objPHPExcel = $objReader->load($fullName);
                    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'CSV');
                    $objWriter->save(str_replace('.' . $fileType, '.csv', $outDir . DIRECTORY_SEPARATOR . $filename));
                }else{
                    //echo "file type is: " . $fileType . "\n";
                }
            }
        }
    }else{
        echo "can't open the directory: " . $baseDir . "\n";
    }
}
Coordinator
Feb 19, 2013 at 11:46 AM
PHPExcel's calculation engine can't fully interpret row and column references in formulae:

change
    =VLOOKUP(D2,Sheet2!A:B,2,FALSE)
to
    =VLOOKUP(D2,Sheet2!A1:B21,2,FALSE)