I'm trying to export data from Mysql and php to an excel file.
but something is wrong.
this is my code:
<?php
header('Content-Type: text/html; charset=UTF-8');
session_start();
if(!isset($_SESSION['usuario']))
{
header('Location: login.php');
}
require('../conexion.php');
$conexion = conexion();
if (mysqli_connect_errno())
{
printf("La conexión con el servidor de base de datos falló: %s\n", mysqli_connect_error());
exit();
}
$consulta = $_SESSION['query'];
echo $consulta; //consulta = SELECT * FROM cotion where status= 'Vea'
$resultado = mysql_query ($consulta, $conexion) or die (mysql_error ());
$registros = mysql_num_rows ($resultado);
if ($registros > 0) {
require_once 'excel/Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
//Informacion del excel
$objPHPExcel->
getProperties()
->setCreator("Creator")
->setLastModifiedBy("setLastModifiedBy")
->setTitle("tittle")
->setSubject("Subject")
->setDescription("Description")
->setKeywords("Keywords")
->setCategory("Category");
$i = 1;
while ($registro = mysql_fetch_object ($resultado)) {
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A'.$i, $registro->pais);
$i++;
}
}
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="ex.xlsx"');
header('Cache-Control: max-age=0');
$objWriter=PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel2007');
$objWriter->save('php://output');
exit;
mysql_close ();
?>
But i only can see it:

but I do not see it in the excel file, I see it in the web browser.
I looked here to do my exports, and download the PHPExcel class from here
Any idea about what could Ido?
Thank you
text/html. Try removing that.headerbut, Still seeing the same ��sechoas @Mark Baker said.. But the problem continues