简体   繁体   中英

PHPExcell Cell coordinate can not be zero-length string

I am using PHPExcel via the Zend framework and want to read entire Excel files into an array of data. I downloaded the final release from this page .

The code I am using is as below :

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;
}

And I get this error:

 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}  

I have searched a lot but found nothing! How can I resolve the problem ?

you definde cell is too short, you can add some cells like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM