Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $conexion = new mysqli('localhost','root','admin123','database',3306);
- if (mysqli_connect_errno()) {
- printf("La conexión con el servidor de base de datos falló: %sn", mysqli_connect_error());
- exit();
- }
- $consulta = "SELECT servicio_No, hora, tipo_Ambulancia, tipo_Traslado, horario, cliente, fecha_Solicitud, hora1, hor, regulador FROM servicio ORDER BY servicio_No";
- $resultado = $conexion->query($consulta);
- if($resultado->num_rows > 0 ){
- date_default_timezone_set('America/Bogota');
- if (PHP_SAPI == 'cli')
- die('Este archivo solo se puede ver desde un navegador web');
- /** Se agrega la libreria PHPExcel */
- require_once 'Classes/PHPExcel.php';
- // Se crea el objeto PHPExcel
- $objPHPExcel = new PHPExcel();
- // Se asignan las propiedades del libro
- $objPHPExcel->getProperties()->setCreator("Trujii") //Autor
- ->setLastModifiedBy(";D") //Ultimo usuario que lo modificó
- ->setTitle("Reporte Excel con PHP y MySQL")
- ->setSubject("Reporte Excel con PHP y MySQL")
- ->setDescription("Reporte de servicios")
- ->setKeywords("reporte servicio")
- ->setCategory("Reporte excel");
- $tituloReporte = "Relación de servicios";
- $titulosColumnas = array('SERVICIO NO', 'HORA', 'TIPO AMBULANCIA', 'TIPO TRASLADO', 'HORARIO', 'CLIENTE', 'FECHA SOLICITUD', 'HORA', 'HOR', 'REGULADOR');
- $objPHPExcel->setActiveSheetIndex(0)
- ->mergeCells('A1:J1');
- // Se agregan los titulos del reporte
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A1',$tituloReporte)
- ->setCellValue('A3', $titulosColumnas[0])
- ->setCellValue('B3', $titulosColumnas[1])
- ->setCellValue('C3', $titulosColumnas[2])
- ->setCellValue('D3', $titulosColumnas[3])
- ->setCellValue('E3', $titulosColumnas[4])
- ->setCellValue('F3', $titulosColumnas[5])
- ->setCellValue('G3', $titulosColumnas[6])
- ->setCellValue('H3', $titulosColumnas[7])
- ->setCellValue('I3', $titulosColumnas[8])
- ->setCellValue('J3', $titulosColumnas[9])
- ->setCellValue('K3', $titulosColumnas[10]));
- //Se agregan los datos de los alumnos
- $i = 4;
- while ($fila = $resultado->fetch_array()) {
- $objPHPExcel->setActiveSheetIndex(0)
- ->setCellValue('A'.$i, $fila['servicio_No'])
- ->setCellValue('B'.$i, $fila['hora'])
- ->setCellValue('C'.$i, $fila['tipo_Ambulancia'])
- ->setCellValue('D'.$i, $fila['tipo_Traslado'])
- ->setCellValue('E'.$i, $fila['horario'])
- ->setCellValue('F'.$i, $fila['cliente'])
- ->setCellValue('G'.$i, $fila['fecha_Solicitud'])
- ->setCellValue('H'.$i, $fila['hora1'])
- ->setCellValue('I'.$i, $fila['hor'])
- ->setCellValue('J'.$i, $fila['regulador']));
- $i++;
- }
- $estiloTituloReporte = array(
- 'font' => array(
- 'name' => 'Verdana',
- 'bold' => true,
- 'italic' => false,
- 'strike' => false,
- 'size' =>20,
- 'color' => array(
- 'rgb' => 'FFFFFF'
- )
- ),
- 'fill' => array(
- 'type' => PHPExcel_Style_Fill::FILL_SOLID,
- 'color' => array('argb' => 'FF220835')
- ),
- 'borders' => array(
- 'allborders' => array(
- 'style' => PHPExcel_Style_Border::BORDER_NONE
- )
- ),
- 'alignment' => array(
- 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
- 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
- 'rotation' => 0,
- 'wrap' => TRUE
- )
- );
- $estiloTituloColumnas = array(
- 'font' => array(
- 'name' => 'Arial',
- 'bold' => true,
- 'color' => array(
- 'rgb' => 'FFFFFF'
- )
- ),
- 'fill' => array(
- 'type' => PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR,
- 'rotation' => 90,
- 'startcolor' => array(
- 'rgb' => '00abdd'
- ),
- 'endcolor' => array(
- 'argb' => '00abdd'
- )
- ),
- 'borders' => array(
- 'top' => array(
- 'style' => PHPExcel_Style_Border::BORDER_MEDIUM ,
- 'color' => array(
- 'rgb' => '143860'
- )
- ),
- 'bottom' => array(
- 'style' => PHPExcel_Style_Border::BORDER_MEDIUM ,
- 'color' => array(
- 'rgb' => '143860'
- )
- )
- ),
- 'alignment' => array(
- 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
- 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
- 'wrap' => TRUE
- ));
- $estiloInformacion = new PHPExcel_Style();
- $estiloInformacion->applyFromArray(
- array(
- 'font' => array(
- 'name' => 'Arial',
- 'color' => array(
- 'rgb' => '000000'
- )
- ),
- 'fill' => array(
- 'type' => PHPExcel_Style_Fill::FILL_SOLID,
- 'color' => array('argb' => '00abdd')
- ),
- 'borders' => array(
- 'left' => array(
- 'style' => PHPExcel_Style_Border::BORDER_THIN ,
- 'color' => array(
- 'rgb' => '3a2a47'
- )
- )
- )
- ));
- $objPHPExcel->getActiveSheet()->getStyle('A1:J1')->applyFromArray($estiloTituloReporte);
- $objPHPExcel->getActiveSheet()->getStyle('A3:J3')->applyFromArray($estiloTituloColumnas);
- $objPHPExcel->getActiveSheet()->setSharedStyle($estiloInformacion, "A4:BD".($i-1));
- for($i = 'A'; $i <= 'J'; $i++){
- $objPHPExcel->setActiveSheetIndex(0)
- ->getColumnDimension($i)->setAutoSize(TRUE);
- }
- // Se asigna el nombre a la hoja
- $objPHPExcel->getActiveSheet()->setTitle('servicio');
- // Se activa la hoja para que sea la que se muestre cuando el archivo se abre
- $objPHPExcel->setActiveSheetIndex(0);
- // Inmovilizar paneles
- //$objPHPExcel->getActiveSheet(0)->freezePane('A4');
- $objPHPExcel->getActiveSheet(0)->freezePaneByColumnAndRow(0,10);
- // Se manda el archivo al navegador web, con el nombre que se indica (Excel2007)
- header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
- header('Content-Disposition: attachment;filename="ReportedeSERVICIOS.xlsx"');
- header('Cache-Control: max-age=0');
- $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
- $objWriter->save('php://output');
- exit;
- }
- else{
- print_r('No hay resultados para mostrar');
- }
- ?>
Add Comment
Please, Sign In to add comment