Last active
August 29, 2015 14:17
-
-
Save ronsuez/94dcff8de42851e6353b to your computer and use it in GitHub Desktop.
PHPExcel Basic Usage - Template importing
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
<?php | |
// Importamos la clase PHPExcel | |
App::import('Vendor', 'Classes/PHPExcel'); | |
$locale = 'es'; | |
$validLocale = PHPExcel_Settings::setLocale($locale); | |
if (!$validLocale) { | |
echo 'Unable to set locale to '.$locale." - reverting to en_us<br />\n"; | |
} | |
$objPHPExcel = PHPExcel_IOFactory::load("../Vendor/phpExcel/templates/reporte-empleados.xlsx"); | |
$objPHPExcel->getProperties()->setCreator("SGPAG") | |
->setLastModifiedBy("SGPAG") | |
->setTitle("Reporte de empleados_gerencia") | |
->setSubject("Reporte de empleados_gerencia") | |
->setDescription("Reporte de empleados_gerencia generado desde el SGPAG"); | |
$inicio = 'A1'; | |
// inicio loop | |
//print_r($empleados); | |
$i = 1; | |
$objPHPExcel->setActiveSheetIndex(0); | |
foreach ($empleados as $emp) { | |
$objPHPExcel->getActiveSheet() | |
->setCellValue('A'.$i, $emp['Empleado']['correo_empresa']) | |
->setCellValue('B'.$i, $emp['Cv']['nombres']) | |
->setCellValue('C'.$i, $emp['Cv']['apellidos']) | |
->setCellValue('D'.$i, $emp['Departamento']['nombre']) | |
->setCellValue('E'.$i, $emp['Cargo']['titulo']); | |
$i++; | |
} | |
//Fin loop | |
$objPHPExcel->getActiveSheet()->setTitle('Listado Emp_Correos'); | |
$objPHPExcel->setActiveSheetIndex(0); | |
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); | |
header('Content-Disposition: attachment;filename="reporte_empleados.xlsx"'); | |
header('Cache-Control: max-age=0'); | |
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); | |
$objWriter->save('php://output'); | |
exit; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment