Ver Mensaje Individual
  #8 (permalink)  
Antiguo 08/06/2016, 10:49
s_AsP
 
Fecha de Ingreso: junio-2016
Mensajes: 1
Antigüedad: 7 años, 10 meses
Puntos: 0
Respuesta: Problema con PHPExcel

<?php

session_start();
require('./lib/lib/PHPExcel/PHPExcel.php');
$id = $_GET['id'];

$conn = new mysqli('127.0.0.1', 'root', 'sl2016', 'glpi');
if (mysqli_connect_errno()) {
printf("La conexión con el servidor de base de datos falló: %s\n", mysqli_connect_error());
}
$sql = "SELECT * FROM glpi_plugin_adminbienes_solicitudes where id_solicitud = $id";
$result = $conn->query($sql);

$objPHPExcel = new PHPExcel;
// set syles
$objPHPExcel->getDefaultStyle()->getFont()->setName('Arial');

$objPHPExcel->getDefaultStyle()->getFont()->setSize(10);

$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);

// writer will create the first sheet for us, let's get it

$objSheet = $objPHPExcel->getActiveSheet();

$objSheet->setTitle('RESULTADOS');

// Se agregan los titulos del reporte
$objSheet->getCell('A1')->setValue('ID');
$objSheet->getCell('B1')->setValue('Fecha');
$objSheet->getCell('C1')->setValue('Nombre De La Imagen');


//Informacion de Columnas y Titulos
if ($result->num_rows > 0) {
$i = 3;
while ($row = $result->fetch_assoc()) {
$objPHPExcel->setActiveSheetIndex(0)
->setCellvalue('A' . $i, $row['id_solicitud'])
->setCellvalue('B' . $i, $row['fecha_solicitud'])
->setCellvalue('C' . $i, $row['producto_solicitud'])
->setCellvalue('D' . $i, $row['cant_producto_solicitud']);
$i++;
}
}

$estiloTituloReporte = array(
'font' => array(
'name' => 'Verdana',
' bold' => true,
' italic' => false,
' strike' => false,
' size' => 16,
' 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' => 'c47cf2'
),
' endcolor' => array(
'argb' => 'FF431a5d'
)
),
' 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' => 'FFd9b7f4')
),
'borders' => array(
'left' => array(
'style' => PHPExcel_Style_Border::BORDER_THIN,
'color' => array(
'rgb' => '3a2a47'
)
)
)
));

$objPHPExcel->getActiveSheet()->getStyle('A1:B1')->applyFromArray($estiloTituloReporte);
$objPHPExcel->getActiveSheet()->getStyle('A3:D3')->applyFromArray($estiloTituloColumnas);
$objPHPExcel->getActiveSheet()->setSharedStyle($estiloInformacion, 'A3:D' . ($i - 1));







//$objWriter->save('pruebaexcel2.xls');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="pruebaexcel5.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
?>