Exportar Excel (phpExcel)
Bom dia....
Mudei de planos quanto a minha exportação para excel, porém continuo tendo problemas...
Os arquivos em questão estao dentro do seguinte caminho...
www/painel/src/view/rrc
PHPExcel (uma pasta com arquivos da biblioteca)
PHPExcel.php (arquivo da biblioteca)
excel.php (arquivo de funções - copiado do exemplo da biblioteca )
resultPrecoXLS.php (arquivo que deveria criar a exportação do arquivo )
Quando eu clico pra gerar o arquivo esta me aparecendo um monte de caracteres na tela ( em anexo a imagem do erro)
Abaixo os códigos em questão.
Fico no aguardo se alguém tiver alguma sugestão.
excel.php
<?php
function activeErrorReporting(){
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
}
function noCli(){
if (PHP_SAPI == 'cli')
die('This example should only be run from a Web Browser');
}
function getHeaders(){
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="01simple.xls"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0
}
?>
**resultPrecoXLS.php **
<?php
require_once 'excel.php';
require_once 'request_precos.php';
activeErrorReporting();
//noCli();
require_once 'PHPExcel.php';
$objPHPExcel = new PHPExcel();
// Set document properties
$objPHPExcel->getProperties()->setCreator("Zenite Sistemas")
->setLastModifiedBy("Zenite Sistemas")
->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Test result file");
// Add some data
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Cód Prod')
->setCellValue('B1', 'Descrição')
->setCellValue('C1', 'Lista')
->setCellValue('D1', 'Preço');
$row = 2;
foreach($_retorno as $res){
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A'.$row , $res['CODPROD'])
->setCellValue('B'.$row, $res['CODPROD'])
->setCellValue('C'.$row, $res['CODPROD'])
->setCellValue('D'.$row, $res['CODPROD']);
$row++;
}
// Rename worksheet
$objPHPExcel->getActiveSheet()->setTitle('Lista de Preços');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
getHeaders();
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;

Discussão (1)
Carregando comentários...