Column string index can not be empty.

Topics: Developer Forum, Project Management Forum
Sep 21, 2007 at 1:21 AM
This is the error I keep getting.
<b>Fatal error</b>: Uncaught exception 'Exception' with message 'Column string index can not be empty.' in /var/www/....../pixel/lib/PHPExcel/Cell.php:440

here is the complete stack trace:
#0 /path/lib/PHPExcel/Cell.php(544): PHPExcel_Cell::columnIndexFromString('')
#1 internal function: PHPExcelCell::compareCells(Object(PHPExcelCell), Object(PHPExcel_Cell))
#2 /path/lib/PHPExcel/Worksheet.php(263): uasort(Array, Array)
#3 /path/lib/PHPExcel/Writer/Excel5.php(105): PHPExcel_Worksheet->getCellCollection()
#4 /path/app/controllers/admin/inboxcontroller.php(643): PHPExcelWriter_Excel5->save('php://output')
#5 /path/vendor/pixel/ActionController.php(228): InboxController->combinedreports()

It was working earlier, and now it has stopped, here is the code basically:

include_once 'PHPExcel.php';
$excel = new PHPExcel();
....snip
$cols = range('A','Z');
$active_sheet = 0;
while (!$rs->EOF){
$excel->setActiveSheetIndex($active_sheet);
$firsttimethrough = true;
foreach ($report as $line) {
$total_cols = count($line);
// write headers, which are the keys of line array
if ($firsttimethrough) {
$headers = array_keys($line);
for ($i=0; $i < $total_cols; $i++) {
$excel->getActiveSheet()->setCellValue($cols$i.$row, $headers$i);
}
$firsttimethrough = false;
$row++;
}
$values = array_values($line);
for ($i=0; $i < $total_cols; $i++) {
$excel->getActiveSheet()->setCellValue($cols$i.$row, $values$i);
}
$row++;
}
// name the sheet
$form_name = substr($rs->fields'form_name',0 ,30);
$excel->getActiveSheet()->setTitle($form_name);
$active_sheet++;
$excel->createSheet();
$rs->MoveNext();
}

// then after that i just write it out to the browser:

include 'PHPExcel/Writer/Excel5.php';
$objWriter = new PHPExcelWriterExcel5($excel);
header("Content-Type: application/octet-stream");
header("Content-disposition:attachment; filename=\"$filename\"");
$objWriter->save('php://output');

its definitely not the Excel5 writer, as I tried the 2007 one and then dug in the code and saw where the error is happening, but Im not sure why its passing and empty string to PHPExcel_Cell::columnIndexFromString('')
Coordinator
Sep 21, 2007 at 8:42 AM
Seems like somewhere " $excel->getActiveSheet()->setCellValue($cols$i.$row, $headers$i);" is passing in a wrong value somehow...

I'll dig deeper into this!
Coordinator
Sep 21, 2007 at 8:45 AM
Are you using column indexes beyond "IV"?
Sep 21, 2007 at 5:30 PM
I verified that $excel->getActiveSheet()->setCellValue($cols$i.$row, $headers$i) (<- the brackets are missing when i post it by the way) is spitting out A1 B1 etc.
Sep 21, 2007 at 6:05 PM
ok now i have an idea about this. today i logged back into the server after it not working last night at all and it works magically. but its a different data set. so im wondering if there was something in the $values$i that is tripping up the parser? maybe there is a way to escape the output so that it wont just choke on it?
Sep 21, 2007 at 6:25 PM
ok so it definitely has something to do with the data being written into the cell, because the script works fine for some result sets and then give out that error on other ones. Is there a way at this point to escape the data? I have tried doing this:
$excel->getActiveSheet()->getCell($lcols$j.$row)->setValueExplicit($values$j, PHPExcelCellDataType::TYPESTRING);

but it still dies. should i try the inline one instead? Ill do that now
Coordinator
Oct 1, 2007 at 7:15 AM

nsbucky wrote:
ok so it definitely has something to do with the data being written into the cell, because the script works fine for some result sets and then give out that error on other ones. Is there a way at this point to escape the data? I have tried doing this:
$excel->getActiveSheet()->getCell($lcols$j.$row)->setValueExplicit($values$j, PHPExcelCellDataType::TYPESTRING);

but it still dies. should i try the inline one instead? Ill do that now

Do you know on which value from your dataset it errors?
Oct 1, 2007 at 5:00 PM
yeah im still trying to track it down, once I can reproduce it i can post it someplace, the thing is that it contains potentially confidential info, which I might not be able to post (and might contain the problem grr) ill post back when I find something.
Coordinator
Oct 1, 2007 at 7:52 PM
You can mail it to maarten A-T phpexcel D-O-T net if you do not want to share this publicly...