0

How to get Excel data into an array in PHP local site. I want to print data in Excel as array in my practice site. I have created Excel in htdocs as test.xlsx. How can I print it's data in PHP?

pnuts
  • 58,317
  • 11
  • 87
  • 139
39467
  • 13
  • 6

2 Answers2

1

First include PhpExcel library into your code then use this

PHPExcel_IOFactory::addSearchLocation($filepath, $savedfilename);
        $objReader = PHPExcel_IOFactory::load($filepath);

        $data = array();
        $worksheet = $objReader->getActiveSheet();
        foreach ($worksheet->getRowIterator(2) as $row) {
            $cellIterator = $row->getCellIterator();
            $cellIterator->setIterateOnlyExistingCells(false);
            foreach ($cellIterator as $cell) {
                $data[$cell->getRow()][$cell->getColumn()] = $cell->getValue();
            }
        }
print_r($data);
Priye Ranjan
  • 422
  • 4
  • 20
0

Can you please look at this link once, I think you can get more idea for your question.

http://www.phpgang.com/how-to-read-excel-file-insert-data-into-mysql-database-using-php_609.html

Jagruti
  • 41
  • 1
  • 4
  • Link only answers aren't good answers for StackOverflow. Put the general gist of the page in your answer, and then it will stil have value here even if the linked page disappears – Mark Baker Jun 30 '15 at 08:14
  • Also, note that the library used in that linked page will not read xlsx files, only xls files, so it won't work as an answer to this question – Mark Baker Jun 30 '15 at 08:15