Import XLSX file into PHP array

Is it possible to import every line of an XLSX file into a line in a PHP array?

+8
php xlsx
source share
3 answers

You can use PHPExcel, which is available here: https://phpexcel.codeplex.com/releases/view/119187

Here is what I use to read xls or xlsx for an array:

 require_once('/path/to/PHPExcel.php'); $filename = "example.xlsx"; $type = PHPExcel_IOFactory::identify($filename); $objReader = PHPExcel_IOFactory::createReader($type); $objPHPExcel = $objReader->load($filename); foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) { $worksheets[$worksheet->getTitle()] = $worksheet->toArray(); } print_r($worksheets); 
+11
source share

I use this:

 include 'simplexlsx.class.php'; $xlsx = @(new SimpleXLSX('myFile.xlsx')); $data = $xlsx->rows(); 

You can use simplexslx from here .

UPDATE

Apparently the link above no longer works. Now you can use this . (Thanks @Basti)

+9
source share

The problem can be solved using the PHPExcel library:

 $data = []; $type = PHPExcel_IOFactory::identify($filepath); $objReader = PHPExcel_IOFactory::createReader($type); $objPHPExcel = $objReader->load($filepath); $rowIterator = $objPHPExcel->getActiveSheet()->getRowIterator(); foreach($rowIterator as $row){ $cellIterator = $row->getCellIterator(); foreach ($cellIterator as $cell) { $data[$row->getRowIndex()][$cell->getColumn()] = $cell->getCalculatedValue(); } } 

where $ filepath is the path to your xls or xlsx file.

+1
source share

All Articles