I am trying to export a table from my database to an excel file, using the library PHPExcel
The structure of my table is:
reg, folio, key, date, place, address, telephone, name, subject, depto1, depto2, state, observations, scan, evidence
and my code PHP
to export is:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$conexion = mysqli_connect ("localhost", "xxxxx", "xxxxxx");
mysqli_select_db ( $conexion, "xxxxxx");
$sql = "SELECT * FROM solicitudes ORDER BY folio DESC";
$resultado = mysqli_query ($conexion,$sql) or die (mysqli_error ());
$registros = mysqli_num_rows ($resultado);
if ($registros > 0) {
require_once 'PHPExcel/Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
//Informacion del excel
$objPHPExcel->
getProperties()
->setCreator("lahuerta")
->setLastModifiedBy("lahuerta")
->setTitle("Exportar Base de Datos")
->setSubject("Tabla")
->setDescription("Documento generado con PHPExcel")
->setKeywords("lahuerta con phpexcel")
->setCategory("solicitudes");
$i = 1;
while ($registro = mysqli_fetch_object ($resultado)) {
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A'.$i, $registro->name);
$i++;
}
}
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="tabla.xlsx"');
header('Cache-Control: max-age=0');
$objWriter=PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel2007');
$objWriter->save('php://output');
exit;
mysql_close ();
?>
I am receiving the following error several times:
Notice: Undefined property: stdClass :: $ name in /home/exportar.php on line 32
I also receive these 3 errors after the aforementioned:
Warning: Can not modify header information - headers already sent by (output started at /home/exportar.php:32) in /home/exportar.php on line 38
Warning: Can not modify header information - headers already sent by (output started at /home/exportar.php:32) in /home/exportar.php on line 39
Warning: Can not modify header information - headers already sent by (output started at /home/exportar.php:32) in /home/exportar.php on line 40
and when I finish the list of errors it shows me some strange encodings:
PKa JG D X [Content_Types] .xml MN 0 " % nY vAa (0 ؖ g w {& i @ nbE { y d8l m X ( ) F ; @ 1_ c) j x /% E y QĿi ! K y3 J < Z1 0? Y L% zV c Ib7 a / l5P1: q r j j0A u "" ( W M ) Tj ({ܲ > O , X * > B ~ Ӥ6 J = oBZ t X4 Cg , QgmrL ٯ c e t Z ? hPv ± u j R } Cv PKa J 78 K_rels / .rels j 0 { { 1F ^ ʠ 2 l $ -}
The version of PHP
is the 5.6
and the extension Zip
I have it enabled.