2

I have used the following code for excel import in php

$filename=$_FILES["file"]["tmp_name"];
$this->load->library("PHPExcel");
$inputFileType = PHPExcel_IOFactory::identify($filename);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($filename);
//$objPHPExcel = PHPExcel_IOFactory::load($file);
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
$allDataInSheet = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
$arrayCount = count($allDataInSheet);

while uploading some xls file getting the error,

Fatal error: Call to undefined method PHPExcel_Shared_ZipArchive::statName() in D:\xampp\htdocs\folder\application\third_party\PHPExcel\Reader\OOCalc.php on line 80 .

I have also used the line

PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP); 

but getting the same error. pls help me resolve the error.

pabha
  • 35
  • 9

2 Answers2

2

Try something in this fashion:

$filename = $_FILES["file"]["tmp_name"];;
//load the excel library
$this->load->library('PHPExcel');
//read file from path
$objPHPExcel = PHPExcel_IOFactory::load($filename );
//get only the Cell Collection
$cell_collection = $objPHPExcel->getActiveSheet()->getCellCollection();
//extract to a PHP readable array format
foreach ($cell_collection as $cell) {
    $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;
Nuri Ensing
  • 1,899
  • 1
  • 19
  • 42
0

I was able to upload only xlsx file and not able to add csv, xls and other format files.
I removed this line from controller:

PHPExcel_Settings::setZipClass(PHPExcel_Settings::PCLZIP);  

It works for me, now I'm able to upload all excel formats.

סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68