EjemplosDuoc.es.tl
  PHPExcel - exportar Masivo
 
Permite exportar varios resultados a un excel en distintas hojas de un mismo excel.
los $_SESSION['exportacion']; // es el resulSet o similar.
Se necesita previamente tener la librería PHPExcel, el formulario, la clase y la conexión al motor deseado.

if(!isset($_SESSION['exportacion']) || count($_SESSION['exportacion']) == 0)
$errores = 'Debe realizar una búsqueda para exportar datos';
else
{
set_include_path(get_include_path() . PATH_SEPARATOR . '../Classes/');
require_once('../Classes/PHPExcel.php');
include 'PHPExcel/IOFactory.php';
 
$hojaActivo = 0;
$objPHPExcel = new PHPExcel();
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load("../archivos/excelActaSAAC.xlsx");
$objPHPExcel->setActiveSheetIndex($hojaActivo);
  $reportes = $_SESSION['exportacion']; // es el resulSet o similar 
$contador = 4;
foreach($reportes as $reporte)
{
for($ind = 0; $ind < count($reporte); $ind++)
$objPHPExcel->setActiveSheetIndex($hojaActivo)->setCellValue(chr((65+$ind)).$contador, ($reporte[$ind]));
$contador++;
}
 
$objPHPExcel->getActiveSheet()->setTitle('Actividades SAAC');
if(isset($_SESSION['exportacion2']) && count($_SESSION['exportacion2']) > 0)
{
$hojaActivo = 1;
$objPHPExcel->setActiveSheetIndex($hojaActivo);
$reportes = $_SESSION['exportacion2'];
$contador = 4;
foreach($reportes as $reporte)
{
for($ind = 0; $ind < count($reporte); $ind++)
$objPHPExcel->setActiveSheetIndex($hojaActivo)->setCellValue(chr((65+$ind)).$contador, ($reporte[$ind]));
$contador++;
}
 
$objPHPExcel->getActiveSheet()->setTitle('Asistencias');
if(isset($_SESSION['exportacion3']) && count($_SESSION['exportacion3']) > 0)
{
$hojaActivo = 2;
$objPHPExcel->setActiveSheetIndex($hojaActivo);
$reportes = $_SESSION['exportacion3'];
$contador = 4;
foreach($reportes as $reporte)
{
for($ind = 0; $ind < count($reporte); $ind++)
$objPHPExcel->setActiveSheetIndex($hojaActivo)->setCellValue(chr((65+$ind)).$contador, ($reporte[$ind]));
$contador++;
}
 
$objPHPExcel->getActiveSheet()->setTitle('Participantes');
if(isset($_SESSION['exportacion4']) && count($_SESSION['exportacion4']) > 0)
{
$hojaActivo = 3;
$objPHPExcel->setActiveSheetIndex($hojaActivo);
$reportes = $_SESSION['exportacion4'];
$contador = 4;
foreach($reportes as $reporte)
{
for($ind = 0; $ind < count($reporte); $ind++)
$objPHPExcel->setActiveSheetIndex($hojaActivo)->setCellValue(chr((65+$ind)).$contador, ($reporte[$ind]));
$contador++;
}
 
$objPHPExcel->getActiveSheet()->setTitle('Secciones');
/* fin proceso */
$objPHPExcel->setActiveSheetIndex(0);
 
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="Reporte'.date("Y_m_d__Hms").'.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
ob_end_clean();
ob_start();
$objWriter->save('php://output');
exit;
}
 
   
 
Este sitio web fue creado de forma gratuita con PaginaWebGratis.es. ¿Quieres también tu sitio web propio?
Registrarse gratis