PHPExcel object passing by reference and Uncaught exception ...

Topics: Developer Forum, Project Management Forum, User Forum
Apr 16, 2009 at 2:18 PM
Edited Apr 16, 2009 at 2:21 PM

I got PHP error: Uncaught exception 'Exception' with message 'Column string index can not be empty.'

function getExcelSheetByParams() is called through AJAX request. getExcelSheetByParams() itself calls FillExcelSheet() which generates main content of $objPHPExcel.  today's morning these two functions were still combined in one (they were like one function). and it all worked. but necessity of making multiple contents in one sheet appeared. so I decided to pass $statTypeSelectedItems array as parameter and to cycle through it filling $objPHPExcel. I divided setting sheet properties and generating main content. ....and after that an error appeared. It appears on lines that are bold. I really don't know how column string index can be connected with setting title and object saving.
I still looking through my code attempting to find some errors. But still without success.

some code:

function FillExcelSheet($stat_target, $stat_type, $dateStart, $dateEnd, $fileFormat, &$prevRowsCount, &$objPHPExcel)
... // $objPHPExcel is filling there

function getExcelSheetByParams($stat_target, $statTypeSelectedItems, $dateStart, $dateEnd, $fileFormat)
$objPHPExcel = new PHPExcel();
$prevRowsCount = 0;
foreach ($statTypeSelectedItems as $stat_type_id => $stat_type)
     $this->FillExcelSheet($stat_target, $stat_type, $dateStart, $dateEnd, $fileFormat, $prevRowsCount, $objPHPExcel);
     // $prevRowsCount is almost a number of rows that have already been inserted.
$objPHPExcel->getActiveSheet()->getPageMargins()->setLeft  (..);
$objPHPExcel->getActiveSheet()->getPageMargins()->setTop  (..);
// adding LOGO to the header
$objDrawing = new PHPExcel_Worksheet_HeaderFooterDrawing();
$report_content = ob_get_contents();

full message:

PHP Fatal error:  Uncaught exception 'Exception' with message 'Column string index can not be empty.' in
...\\lib\\PHPExcel\\Cell.php:573\nStack trace:\n#0
...\\lib\\PHPExcel\\Worksheet.php(399): PHPExcel_Cell::columnIndexFromString('')\n#1
...\\lib\\PHPExcel\\Worksheet.php(371): PHPExcel_Worksheet->sortCellCollection()\n#2
...\\lib\\PHPExcel\\Writer\\Excel2007\\StringTable.php(79): PHPExcel_Worksheet->getCellCollection()\n#3
...\\lib\\PHPExcel\\Writer\\Excel2007.php(273): PHPExcel_Writer_Excel2007_StringTable->createStringTable(Object(PHPExcel_Worksheet), Array)\n#4
...\\lib\\common.lib.php(4183): PHPExcel_Writer_Excel2007->save('php://output')\n#5
...\\lib\\ajax_chain.php(252): site->getExcelSheetByParams('russia', Array, '07/2008', '02/2009', 'excel2007')\n#6 {main}\n  thrown in
...\\lib\\PHPExcel\\Cell.php on line 573, referer: ...export_engine.php
Apr 16, 2009 at 2:49 PM
I commented out all content of FillExcelSheet().
I will uncomment it part-by-part trying to find something.
Apr 16, 2009 at 3:05 PM
well. i found an error in fillExcelSheet()
setCellValue('B'.($ind+$prevRowsCount), ...)

I lost some braces and the string above was looked like setCellValue('B'.$ind+$prevRowsCount, ...)
I had to add $prevRowsCount variable. I added it, and put braces everywhere. and I lost some  there.