Last active
August 29, 2015 14:17
-
-
Save ronsuez/034ab91cc0e878b6bd60 to your computer and use it in GitHub Desktop.
PHPExcel - Read File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function readExcel(){ | |
// Include PHPExcel_IOFactory | |
App::import('Vendor', 'Classes/PHPExcel'); | |
$inputFileName = "../Vendor/phpExcel/docs/vacas-empleados.xlsx"; | |
// Read your Excel workbook | |
try { | |
$inputFileType = PHPExcel_IOFactory::identify($inputFileName); | |
$objReader = PHPExcel_IOFactory::createReader($inputFileType); | |
$objPHPExcel = $objReader->load($inputFileName); | |
ini_set('memory_limit', '256M'); | |
set_time_limit(0); | |
} catch(Exception $e) { | |
die('Error loading file "'.pathinfo($inputFileName,PATHINFO_BASENAME).'": '.$e->getMessage()); | |
} | |
$total_sheets=$objPHPExcel->getSheetCount(); | |
$allSheetName=$objPHPExcel->getSheetNames(); | |
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0); | |
$highestRow = $objWorksheet->getHighestRow(); | |
$highestColumn = $objWorksheet->getHighestColumn(); | |
$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); | |
for ($row = 2; $row <= $highestRow;++$row) | |
{ | |
for ($col = 0; $col <$highestColumnIndex;++$col) | |
{ | |
$value=$objWorksheet->getCellByColumnAndRow($col, $row)->getValue(); | |
$arraydata[$row-1][$col]=$value; | |
} | |
} | |
$date = date('Y-m-d'); | |
$datetime = date('Y-m-d'); | |
foreach ($arraydata as $key => $value){ | |
$insert = | |
$this->SolVacacione->query("INSERT | |
INTO sol_vacaciones(ficha_empleado,cantidad_dias,observaciones_rrhh,fecha_inicio,fecha_fin,fecha_reintegro,fecha_enviado,fecha_revision,fecha_aprobado,fecha_firmado,fecha_cancelacion) | |
VALUES(\"$value[0]\",$value[3],\"Carga de historico de vacaciones\",\"$date\",\"$date\",\"$date\",\"$datetime\",\"$date\",\"$date\",\"$date\",\"$date\")"); | |
} | |
$this->set('arraydata',$result); | |
//$this->set('result',$result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment