0
votes

This following code simply ignore all empty cells in my excelsheet.

Is there any way to read empty cell or replace them to "Null" values?

See the code here---https://arjunphp.com/how-to-use-phpexcel-with-codeigniter/

$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() 
1
That's because it reads the cellcollection directly, so it will only read cells that "exist"...... why not look at some of the PHPExcel documentation to see what functions are actually available in PHPExcel? - Mark Baker
Hello Mark.. I couldnt find any solution yet :( Problem is in this following line.. $data_value = $objPHPExcel->getActiveSheet()->getCell($cell)->getValue(); Is there not any way to get all cell whether cells are empty..for instance ($data_value = $objPHPExcel->getActiveSheet()->getCell($cell)->getValue('all);) ? - princeexpedition
I think solution would be this... $data = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true); - princeexpedition

1 Answers

0
votes

you're try to wrong way, in this way you only get the last active cell value and if you try to get empty cell cell value in middle you're not able to get value. and you use some PhpSpreadsheet function and also some time you try get value using class object. check your code one more time.