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?
Asked
Active
Viewed 1,060 times
0
-
http://stackoverflow.com/questions/563670/reading-an-excel-file-in-php – Keith A Jun 30 '15 at 07:16
-
First off, are you talking about a real xlsx file, created with MS Excel? Or simply a csv or html markup file with an extension of .xlsx? – Mark Baker Jun 30 '15 at 07:27
-
Consider using a library like [PHPExcel](https://github.com/PHPOffice/PHPExcel) – Mark Baker Jun 30 '15 at 07:27
2 Answers
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
-
Or you could simply use the HTML Writer and save the output to php://output.... even fewer lines of code – Mark Baker Jun 30 '15 at 11:42
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