Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何读取PHPExcel中的空单元格?_Php_Codeigniter_Phpexcel - Fatal编程技术网

如何读取PHPExcel中的空单元格?

如何读取PHPExcel中的空单元格?,php,codeigniter,phpexcel,Php,Codeigniter,Phpexcel,下面的代码只是忽略我的Excel工作表中的所有空单元格 有没有办法读取空单元格或将其替换为“Null”值 请参见此处的代码--- 你们试图以错误的方式,这样你们只能得到最后一个活动单元格的值,若你们试图在中间得到空单元格的值,你们就不能得到值。使用一些PhpSpreadsheet函数,有时还尝试使用类对象获取值。再次检查您的代码。这是因为它直接读取cellcollection,所以它只读取“存在”的单元格。。。。。。为什么不看看一些PHPExcel文档,看看PHPExcel中实际提供了哪些功能?

下面的代码只是忽略我的Excel工作表中的所有空单元格

有没有办法读取空单元格或将其替换为“Null”值

请参见此处的代码---


你们试图以错误的方式,这样你们只能得到最后一个活动单元格的值,若你们试图在中间得到空单元格的值,你们就不能得到值。使用一些PhpSpreadsheet函数,有时还尝试使用类对象获取值。再次检查您的代码。

这是因为它直接读取cellcollection,所以它只读取“存在”的单元格。。。。。。为什么不看看一些PHPExcel文档,看看PHPExcel中实际提供了哪些功能?你好,马克。。我还找不到任何解决方案:(问题在下面这行.$data\U value=$objPHPExcel->getActiveSheet()->getCell($cell)->getValue();是否有任何方法可以获取所有单元格,无论单元格是否为空.。例如($data\U value=$objPHPExcel->getActiveSheet()->getCell($cell)->getValue('all);)?我认为解决方案是…$data=$objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
$file = './files/test.xlsx';
//load the excel library
$this->load->library('excel');
//read file from path
$objPHPExcel = PHPExcel_IOFactory::load($file);
//get only the Cell Collection
$cell_collection = $objPHPExcel->getActiveSheet()->getCellCollection();

$maxCell = $objPHPExcel->getHighestRowAndColumn();
$newdata = array();
//extract to a PHP readable array format
foreach ($cell_collection as $cell) {

    I tried this following code 
    $newdata = $objPHPExcel->rangeToArray($cell . $maxCell['column'] . $maxCell['row']);
    $newdata = array_map('array_filter', $data);
    $newdata = array_filter($data);

    $column = $objPHPExcel->getActiveSheet()->getCell($cell)->getColumn();
    $row = $objPHPExcel->getActiveSheet()->getCell($cell)->getRow();
    $data_value = $objPHPExcel->getActiveSheet()->getCell($cell)->getValue();
   //header will/should be in row 1 only. of course this can be modified to suit your need.
    if ($row == 1) {
       $header[$row][$column] = $data_value;
    } else {
       $arr_data[$row][$column] = $data_value;
    }
}
//send the data in an array format
$data['header'] = $header;
$data['values'] = $arr_data;

print_r($newdata);

Get this error messgae... Fatal error: Call to undefined method PHPExcel::getHighestRowAndColumn()