Skip to content

Instantly share code, notes, and snippets.

@SuryaElite
Created September 9, 2014 15:53
Show Gist options
  • Save SuryaElite/462bad9b4377535e4e76 to your computer and use it in GitHub Desktop.
Save SuryaElite/462bad9b4377535e4e76 to your computer and use it in GitHub Desktop.
Convert XLSX or XLS file to Array in PHP
<?php
function convertXLStoArray($infile, $outfile){
if(!file_exists($infile) || !is_readable($infile) || !file_exists($outfile) || !is_readable($outfile))
return FALSE;
$fileType = PHPExcel_IOFactory::identify($infile);
$objReader = PHPExcel_IOFactory::createReader($fileType);
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($infile);
echo $objPHPExcel->getSheetCount(),' worksheet',(($objPHPExcel->getSheetCount() == 1) ? '' : 's'),' loaded<br /><br />';
foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
$arrayData[$worksheet->getTitle()] = $worksheet->toArray();
}
var_dump($arrayData);
}
@guillermo888
Copy link

understand $infile, $outfile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment