Skip to content

Instantly share code, notes, and snippets.

@mig1098
Last active March 19, 2019 16:56
Show Gist options
  • Save mig1098/5de184a0401b9bd0ec37c8d380a31c2f to your computer and use it in GitHub Desktop.
Save mig1098/5de184a0401b9bd0ec37c8d380a31c2f to your computer and use it in GitHub Desktop.
Read data from excel. PHPExcel library
<?php
include('../PHPExcel/PHPExcel/IOFactory.php');
//@param $temp_file path name of file or tmp_name from input file
function leerArchivoExcelCsv($temp_file){
$arrayData = array();
$inputFileName = $temp_file;
/*check point*/
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
$data = array(1,$objPHPExcel->getActiveSheet()->toArray(null,true,true,true));
//mgprint($data);
if($data[0]==1){
$ff=1;
foreach($data[1] AS $row){
if($ff == 1){ $ff++; continue; }//primera linea son titulos, no se considera
$row1 = array();
foreach($row AS $column){
$row1[] = $column;
}
$arrayData[] = $row1;
}
}
return $arrayData;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment