Spreadsheet download using the PHPExcel class

-3

I found this phpexcel class, I can generate xls files fetching MySQL data. It Works very well. But I need to get a worksheet that is stored as a template in the bank and just a few blank fields.

I want to get this worksheet, load, fill cells, and then download it.

    
asked by anonymous 25.11.2014 / 18:09

2 answers

1

To generate XLSX use

Set the XLSX name to $ xlsName with the extension. Example: $ xlsName = 'test.xlsx';

$objPHPExcel = new PHPExcel();

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

For XLS use

Set the $ xlsName name of the XLS with the extension. Example: $ xlsName = 'test.xls';

$objPHPExcel = new PHPExcel();

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

To force the download of an excel spreadsheet it is necessary to define the header, informing how the content should be handled by the browser and invoking the save() method of some writer

//definição do cabeçalho
header('Content-Type: application/vnd.ms-excel;');
header('Content-Disposition: attachment;filename=plan.xls');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: max-age=0');

//cria uma planilha no formato do excel 2003
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');

The latest versions, documentation, tutorials, etc. can be found at: PHPExcel

    
27.11.2014 / 15:19