Fatal Error with getCell('name')

Topics: Developer Forum
Mar 8, 2010 at 7:40 AM
require_once './Classes/PHPExcel/IOFactory.php';

$objReader = PHPExcel_IOFactory::createReaderForFile("sumatorio.xlsx");
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load("sumatorio.xlsx");
$objWorksheet = $objPHPExcel->getActiveSheet();
echo $objWorksheet->getCell('sumatorio1')->getValue()."<br />";
echo $objWorksheet->getCell('total')->getCalculatedValue();

Error:
Fatal error: Uncaught exception 'Exception' with message 'Column string index can not be longer than 3 characters.' in
 Z:\home\prueba\www\Classes\PHPExcel\Cell.php:640 Stack trace: #0 Z:\home\prueba\www\Classes\PHPExcel\Worksheet.php(996):
 PHPExcel_Cell::columnIndexFromString('SUMATORIO') #1 Z:\home\prueba\www\index.php(10): PHPExcel_Worksheet->getCell('sumatorio1')
 #2 {main} thrown in Z:\home\prueba\www\Classes\PHPExcel\Cell.php on line 640
Coordinator
Mar 9, 2010 at 8:49 PM

getCell will work as long as the name isn't a sequence of letters followed by a sequence of digits, otherwise it's interpreted as a cell reference like IV256; a name like SUMATORIO will work, but SUMATORIO1 won't.

The logic doesn't test that the name is too long to be a cell reference. I'll make a change to the test for named ranges so that it will work correctly for names that do follow this pattern where the letter sequence is too long to be a cell reference.

Coordinator
Mar 9, 2010 at 8:50 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Mar 9, 2010 at 9:41 PM

As a quick fix, you can change line 64 in /Classes/PHPExcel/Calculation.php that reads

const CALCULATION_REGEXP_CELLREF = '(((\w*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?([a-z]+)\$?(\d+)';

to

const CALCULATION_REGEXP_CELLREF = '(((\w*)|(\'[^\']*\')|(\"[^\"]*\"))!)?\$?([a-z]{1,3})\$?(\d+)';
Mar 16, 2010 at 10:27 AM

Thank you very much!!! everything works.