0

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

我使用的代码如下:

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}  

我搜索了很多,但一无所获!我该如何解决这个问题?

4

1 回答 1

1

你定义的单元格太短,你可以像这样添加一些单元格:

$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');

于 2017-05-05T02:13:56.593 回答