PHPExcell Cell坐标不能是零长度字符串

时间:2013-05-11 13:13:21

标签: php zend-framework phpexcel

我通过Zend框架使用PHPExcel,并希望将整个Excel文件读入数据数组。我从this page下载了最终版本。

我使用的代码如下:

static function Read_Excel($inputFileName)
{
    $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
    $objReader = PHPExcel_IOFactory::createReader($inputFileType);      
    $objReader->setReadDataOnly(true);
    $objPHPExcel = $objReader->load($inputFileName);    
    $objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
    $highestRow = $objWorksheet->getHighestRow();
    $highestColumn = $objWorksheet->getHighestColumn();
    $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
    if($highestRow <=0 || $highestColumnIndex<=0)
        return false;
    $arr_data = array();
    for ($row = 1; $row <= $highestRow; $row ++) {
        for ($col = 0; $col <= $highestColumnIndex; $col ++) {
            $value = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
            if (is_array($arr_data))
                $arr_data[$row - 1][$col] = $value;
        }
    }
    return $arr_data;
}

我收到了这个错误:

 Message: Cell coordinate can not be zero-length string
Stack trace:

#0 C:\xampp\htdocs\wimax.shabdiznet.com\library\PHPExcel\Reader\Excel2007.php(935): PHPExcel_Cell::coordinateFromString('')
#1 C:\xampp\htdocs\wimax.shabdiznet.com\application\models\Functions.php(30): PHPExcel_Reader_Excel2007->load('C:\xampp\tmp\ph...')
#2 C:\xampp\htdocs\wimax.shabdiznet.com\application\controllers\ImportController.php(56): Application_Model_Functions::Read_Excel('C:\xampp\tmp\ph...')
#3 C:\xampp\htdocs\wimax.shabdiznet.com\library\Zend\Controller\Action.php(516): ImportController->indexAction()
#4 C:\xampp\htdocs\wimax.shabdiznet.com\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('indexAction')
#5 C:\xampp\htdocs\wimax.shabdiznet.com\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#6 C:\xampp\htdocs\wimax.shabdiznet.com\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#7 C:\xampp\htdocs\wimax.shabdiznet.com\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#8 C:\xampp\htdocs\wimax.shabdiznet.com\public\index.php(25): Zend_Application->run()
#9 {main}  

我搜索了很多但没有发现任何东西!我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

你定义的细胞太短,你可以添加一些细胞 像这样:

  

$ cell = array('A1','B1','C1','D1','E1','F1','G1','H1','I1','J1','K1 ”, 'L1', 'M1', 'N1', 'O1', 'P1', 'Q1', 'R 1', 'S1', 'T1', 'U1', 'V1', 'W1', 'X1', 'Y1', 'Z1');