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.

3
  • 1
    Possible duplicate of PHPExcel ZipArchive not found Commented May 3, 2017 at 9:17
  • I suggest you to replace your PHPExcel with fresh version Commented May 3, 2017 at 9:19
  • Yes already did those things. Commented May 3, 2017 at 9:21

2 Answers 2

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;
Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

Please add some explanation to your answer such that others can learn from it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.