How do I solve "Uninitialized string offset: 1"

Topics: Developer Forum, User Forum
Jun 26, 2009 at 1:27 PM

Can anybody help me guide me in the right direction how to debug this result:


Notice: Uninitialized string offset: 1 in C:\Program\Apache Software Foundation\Apache2.2\htdocs\hpq\portal\lib\phpexcel\Classes\PHPExcel\Writer\Excel5\Parser.php on line 1205

Fatal error: Uncaught exception 'Exception' with message 'Syntax error: ), lookahead: , current char: 1' in C:\Program\Apache Software Foundation\Apache2.2\htdocs\hpq\portal\lib\phpexcel\Classes\PHPExcel\Writer\Excel5\Parser.php:1406 Stack trace: #0 C:\Program\Apache Software Foundation\Apache2.2\htdocs\hpq\portal\lib\phpexcel\Classes\PHPExcel\Writer\Excel5\Parser.php(1312): PHPExcel_Writer_Excel5_Parser->_fact() #1 C:\Program\Apache Software Foundation\Apache2.2\htdocs\hpq\portal\lib\phpexcel\Classes\PHPExcel\Writer\Excel5\Parser.php(1272): PHPExcel_Writer_Excel5_Parser->_term() #2 C:\Program\Apache Software Foundation\Apache2.2\htdocs\hpq\portal\lib\phpexcel\Classes\PHPExcel\Writer\Excel5\Parser.php(1220): PHPExcel_Writer_Excel5_Parser->_expression() #3 C:\Program\Apache Software Foundation\Apache2.2\htdocs\hpq\portal\lib\phpexcel\Classes\PHPExcel\Writer\Excel5\Parser.php(1207): PHPExcel_Writer_Excel5_Parser->_condition() #4 C:\Program\Apache Software Foundation\Apache2.2\htdocs\hpq\portal\lib\phpexcel\Classes\PHPExcel\ in C:\Program\Apache Software Foundation\Apache2.2\htdocs\hpq\portal\lib\phpexcel\Classes\PHPExcel\Writer\Excel5\Parser.php on line 1406



The thing is that I am reading from database and trying to write out first column (title-columns) and then the data for corresponding columns. There are several types of data which should be ok but I can't see where the issue lies. The code where this probably gets stuck looks like following:


    // write column-titles on first row
    for ($i = 0;$i < mysql_num_fields($result);$i++) {
        $columnname = mysql_fetch_field($result,$i);
        $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($i,1, $columnname->name);

    // write the values
    $rowloop = 2;
    while($row = mysql_fetch_row($result)) {
        while ($loopvar < mysql_num_fields($result)) {
        $loopvar = 0;


Any ideas?


Jun 26, 2009 at 10:14 PM

It looks like you have some formulas in your workbook which Excel5 writer cannot handle.

If this is the case, there is a bug you can vote for here:

If you post the formula, maybe we can help finding a workaround.


Jun 27, 2009 at 10:11 AM

There is no formula in the Excel file, the data written to Excel file is fetched from database and is raw data (some text and some dates).

I don't know if there could be something with the data in the columns from database but how do I know where to begin looking?


Thank you for the reply btw, unfortunately I don't think it's related to a specific formula since there are none (unless there is some formula written unknown to me).

Jun 29, 2009 at 12:32 AM

Check your strings whether some of them start with '=' (equals sign). If you want to insert strings then you should really use

$cell->setValueExplicit($string, PHPExcel_Cell_DataType::TYPE_STRING);

rather than


Because in the event that the $string accidentally begins with '=' (without the quotes) then it will trigger the formula parser (just like in Excel) and PHPExcel will try to insert a formula. This might be what is causing the error.