PHPExcel exception error “cell cordinate can not be zero-length string” trying simple example to generate a xls file

Topics: Developer Forum, Project Management Forum
Aug 17, 2012 at 10:11 AM

I just asked this question in StackOverflow through this link. In fact, I'm trying to generate a xls template in my web application and for that, I'm using PHPExcel. I use a personalized framework (PHPFW) and also ZendFramework. I'm trying to do my first test using the example: 01simple-download.xls. But when the file is downloaded in my application and I open it using Excel mac 2008, I have the following error message:

There was an error: Cell Coordinate can not be zero-lenght string.

It's being blocked in the file Cell.php, in the function:

public static function coordinateFromString($pCoordinateString = 'A1')
	{
		if (preg_match("/^([$]?[A-Z]{1,3})([$]?\d{1,7})$/", $pCoordinateString, $matches)) {
			return array($matches[1],$matches[2]);
		} elseif ((strpos($pCoordinateString,':') !== FALSE) || (strpos($pCoordinateString,',') !== FALSE)) {
			throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells');
		} elseif ($pCoordinateString == '') {
			throw new PHPExcel_Exception('Cell coordinate can not be zero-length string');
		}

		throw new PHPExcel_Exception('Invalid cell coordinate '.$pCoordinateString);
	}

So it's entering in the last 'elseif' condition, but I'm just using the following example code:

 public function bulkUploadTemplateExcel($ctx) {
        /** Error reporting */
        error_reporting(E_ALL);
        ini_set('display_errors', TRUE);
        ini_set('display_startup_errors', TRUE);
        date_default_timezone_set('Europe/London');

        if (PHP_SAPI == 'cli')
            die('This example should only be run from a Web Browser');

        // Create new PHPExcel object
        $objPHPExcel = new PHPExcel();
        // Set document properties
        $objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
        ->setLastModifiedBy("Maarten Balliauw")
        ->setTitle("Office 2007 XLSX Test Document")
        ->setSubject("Office 2007 XLSX Test Document")
        ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
        ->setKeywords("office 2007 openxml php")
        ->setCategory("Test result file");

        // Add some data
        $objPHPExcel->setActiveSheetIndex(0)
        ->setCellValue('A1', 'Hello')
        ->setCellValue('B2', 'world!')
        ->setCellValue('C1', 'Hello')
        ->setCellValue('D2', 'world!');

        // Miscellaneous glyphs, UTF-8
        $objPHPExcel->setActiveSheetIndex(0)
        ->setCellValue('A4', 'Miscellaneous glyphs')
        ->setCellValue('A5', '�����������������');

        // Rename worksheet
        $objPHPExcel->getActiveSheet()->setTitle('Simple');


        // Set active sheet index to the first sheet, so Excel opens this as the first sheet
        $objPHPExcel->setActiveSheetIndex(0);

        // Redirect output to a client�s web browser (Excel5)
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="01simple.xls"');
        header('Cache-Control: max-age=0');

        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output');

        exit;
}

Any idea of why am I getting this exception error?

Aug 17, 2012 at 10:54 AM

Problem solved! it was just replace the version for the one found at gitHub.