PHPExcel output weird character - phpexcel

$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->SetCellValue('A' . 1, 'No');
$objPHPExcel->getActiveSheet()->SetCellValue('B' . 1, 'Date');
$objPHPExcel->getActiveSheet()->SetCellValue('C' . 1, 'Location');
$objPHPExcel->getActiveSheet()->SetCellValue('D' . 1, 'Vehicle');
$objPHPExcel->getActiveSheet()->SetCellValue('E' . 1, 'Mode');
$objPHPExcel->getActiveSheet()->SetCellValue('F' . 1, 'Super Relief Name');
$objPHPExcel->getActiveSheet()->SetCellValue('G' . 1, 'NRIC');
$objPHPExcel->getActiveSheet()->SetCellValue('H' . 1, 'Shift');
$objPHPExcel->getActiveSheet()->SetCellValue('I' . 1, 'Receipt No.');
$objPHPExcel->getActiveSheet()->getStyle("A1:I1")->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->setTitle("schedule");
ob_end_clean();
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . date("Y-m-d") . '_Schedule.xlsx"');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_end_clean();
$objWriter->save('php://output');
$objPHPExcel->disconnectWorksheets();
unset($objPHPExcel);
It created a paragraph of weird character
PKڢIDG�D�X�[Content_Types].xml��MN�0���"�%nY ��vAa �(0����ؖg�w{&i�#�nbE�{��y��d۸l m������X�(���)���F���;#1_������c)j�x/%��E��y� �QĿi!��K�y3�J<���Z1�0?Y�L%zV c��Ib7�����a/l٥P1:�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��PKڢID�78�K_rels/.rels���j�0��{ �{���1F�^ʠ�2��l��$���-}�y����Î��O��v�y�;�؋Ӱ.JP���޵^������Yű�3G�Ww�g)����>�qQC��D����b!�]�i$L��3����2n���oT�:Z �h�����[��4�ი��]��yN�,ە�>�>�j -' V�)�#��EF^6��n���8q"K��H��>_ׄ����eƏ�<⇄�Ud�v�� T�PKڢID�$�V��xl/_rels/workbook.xml.rels���j�0D�� ��ZvZJ)�s)�\[����LlIh7m��UH��Ĭؙ�H���8�OL���*J�M���|4��g��[=� &$��w�74�r}$�M<)p��EJ2GME���MҨ9��ɨ�^w(We�$���O�� ��V �)��C��_�9���J�$���/�:dG]d���WK�s��s��<�[�V�tB��)?��������0_!��!��4�E�ǩy���PKڢID���I�:docProps/app.xml�S�n�0��+�9�0��bH7��b�vgN�c��$�����';���;M�G��鉤���uE��l��\��#oBe�q#���>��|.x܈����.���-R�#�`�"t���5N�*6�W�K �-����:x��7PKڢIDs�{Y��xl/theme/theme1.xml�YOo�6��S���l�u�:E���֦ �C��DK�)Q 餾 �q��aݰˀ�v�h�]�O����� {�c���6iSlC��-������Q�|�^��!���k9"����]��hx�c!�p`�ҵ�DZW�>��7UDb��<���kEJ���-}���"OIk.b�`(B;����n6m;�4�P�c�zs2�>A�����`>`��(�M�L��D�"�S'��s�gbֵ#N��F䞲�R�B�j��޺l/��ZC�� �OIW�fN'������v����U�`0��%��},uV�����<5P��ʻ��n��o��7z���Q÷*����4��v��w+���o��o��^�o����6�n��"F�� :��22KȄ��Fx����P��� �D��k1���yp�� R��L��>�ǂ�L�$X[)�|�2��B�4U]��CFT�O|��1z�����'��9~�����«8 u������������Wf�������o�~i*���G��6�2g�E��(pHp����3�G�λ-������t=��LQ�Z׀���Fs�e�tsfIh.f:n�C�����f)�djbُHM�=��!I�B��b �Ciͯ��\��Bw(�ajtɈ����*�!.slu�7��Q�3�rXGBB`fbIX͍��±Qc3y�Ȥ��\�5�K� �h)M47ż��5���]6��H��Ԅ��9ב;|ڏp�u�I�c?�Sآ�qeT��3$Cp�6ܷ)QgK�[4��$[� SJ^��9�`����V�c���l3 u�}�^���c�(��p����g���x_��W�w�B������U)��^;g�m�'��5g��̋���!L惜h���<��j�P�� �>�*:�p b�\B(K֡D)�p����ί�l���Ž�X����n���%�|J]P+cpZa�Ko&�)����xfi�K�ٚ7!o�^&8�f!6 f$��^0X���C$#�2F���uJ�u^�5M�F�ͤ�&H�8w�8���X�����,���h�5=�8�Z���1N���Jfaҵ|U���d>i�y[:���D�B�,��*_Z��I*������|�_W�V����O��L&�Wkf�a��g���(8Bc6��v��P GEs1��n����_f���>ev`�F��I-�<^ꐏ4��5���)�s4�{wM�v.4�� �zA 0��h��BE�PQ(�q�e�^�"S ��v�+9��V��(ra��i��J�"AȞ*�|3����Fe�Y�+��wL e�����P��&�#r�ɠ٦����p��6^�=��g�E\��kG�ƛ�pƣ�i������Mᚂ�/(�T���oG|���%��x�S��rr:w4�2Vo���B�i���Ssvk�����l��k�家WS��.2�h��,>��w�~4cJ������������?PKڢIDۃ���cxl/sharedStrings.xmle�KK�0����p�6�.D%�]\��>�!=� �eΩ��7�Bh�����_1�O��s��� 0�<�t������I� 9��Hp���E�&�1�;)�:���\05g�5n��%��f&��1ȫ�����bM�c�S^pZ�׊���d����#��q˞�5�fo�;:o�.���{YV1a�����]`�O���o��}a1��ߒ�%�PKڢID�O � xl/styles.xmlՔMk�0���B�D녖6�i��CCi�Ыl�m}i����W��k�,�^ ��3�Fό����QIr���Mnw���L-t�����#%���42zG��w�Ó���'ܹ�W~�����Q��v��c��#qwkz�~�1Vq��m��{x�II���>0Ņ�y�U(t�2�ƌ�(����E��(�iI�\�!be;��V�m��2��F?I�Wi,�m�Ѣ�M_�5W3��KQZDo�'�<��s�!��-^�Ӟ#�Յw�lN=,������S�������P�]X�g+�%���e���~�΅'�,�����H���g� G�K�KB/Φ��f�D'`״�^a�;6o��T�����<&�k��U�-��_�x��}��� E�DL���K:cūLJihA�咆ۋ� Ri��a��9N��SY���цK篧���/S���36�ϟ�������l����m�p33���˸4��D����g�c�}ѐ��!�Yjh� �p�2��_���D�Q����5�K�������PKڢIDg����xl/workbook.xml�Q]O1|ﯰ�^���Fq�ZJ��TR���{� ��K�_ߵChy��zfwǞ����;��L����^ &ZwJ��\�}'�v1���#�|�f���~����%%m��2��JRr,%-���^�IL�3��ua��:�mi(�u�}�y��Ya��G#��f��A$�Ӆ-ш��z5��ۃK�S��=���I�4�OX%��^yJ&t,����/ί���� ��~?7�P��{�;_�Ц�6z�$'��/�������r�I1`�rSsi�z|��bDc���b(�ݘ�k[�і�za�xA�j������g=��p�ˣ��젺������XEh���؉gEc�l��K�C����q\�0`[�"��=�Fȥ�������o��5�ar�#s?�ר���y�t�PKڢIDÊ�%��xl/worksheets/sheet1.xml�U�r�0��+4�ײ��ۙfq��t��Ҝi�XS�JRrӯ/H-��z�������\E+Q��d4f��ԛ9{}Y~��"��\��9{�.�f;4[���Lm�:,X00j;g�s�4�m�A���t��ɹ#�lbK6\O������8�R7��|`���1)sЮvb#qGw��,,[�B�G��a����h"[�97pGWg-�$7��#��ŝ����W)2��ٷ��.0ᇄ�=�#��Ϡ q �k_�5���De��n��� �ʙj� wW�VTzoM��/�ӧ�+P��#��t����r��2��.. ��rg�]OF',jJs�'_�q��<�^��;���E�._���O�_)�ă!�pF1�+T��,�(��a\�>�j�8�3����>�f�8�3�C�i�q;d���!��ϸ2�t��*�>[]ڦ��5o�9K���*��I��t���F��g���CU��#Jo����Qk���{�:e�?Դ>z�ў����1ق�gk��/�K�K��*d�|�����una�vEX �f?~�q�<�J���F|߹��U#)��G�,2���a�S��9�[-s��c_gt����#e���,�#�4�Y�_s�L�`�����2����m�7)\�,�:�2ċ�LS0��A�� ��1ڃ�4��Ez�.���n&��F{�)D��B��UԼ2�u�ne�#��*^��ԧ֙���tF}���v���_PKڢID�KR"x�#xl/worksheets/_rels/sheet1.xml.relsM�1!{_A��#c�q����p+a!,1�{)-'��y�����$�p�(bW�����~ݟAIG�0&_X��|��}4b5&,B�����#e*�x�gi���uE�BO�h�I����PKڢIDG�D�X�[Content_Types].xmlPKڢID�78�K�_rels/.relsPKڢID�$�V���xl/_rels/workbook.xml.relsPKڢID���I�:�docProps/app.xmlPKڢIDJJ�ErtdocProps/core.xmlPKڢIDs�{Y��xl/theme/theme1.xmlPKڢIDۃ���c�xl/sharedStrings.xmlPKڢID�O � � xl/styles.xmlPKڢIDg����4xl/workbook.xmlPKڢIDÊ�%���xl/worksheets/sheet1.xmlPKڢID�KR"x�# xl/worksheets/_rels/sheet1.xml.relsPK��
It works at localhost, but once I host it to hosting server it got problems.

If it helps, the headings that I'd normally send when using the Excel2007 Writer are:
// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="01simple.xlsx"');
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

Related

While exporting to XLS output is garbage even with correct headertypes

I have tried some solutions provided in other questions about exporting to Excel sheet using PHP,still not working.Also I referred to PHPExcel library examples still stuck.
Here's my code.
<?php
ob_start();
require_once 'Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties() ->setCreator("MeritTrac")
->setTitle("PHPExcel Test document")
->setSubject("PHPExcel Subject")
->setDescription("This is generatred by PHPExcel");
$objPHPExcel ->setActiveSheetIndex(0)
->setCellValue('A1','Hello')
->setCellValue('B1','Test')
->setCellValue('C1','Color')
->setCellValue('D1','World');
$objPHPExcel ->setActiveSheetIndex(0)
->setCellValue('A4','Miscellaneous Glyph')
->setCellValue('A5','ífá');
$objPHPExcel ->setActiveSheetIndex(0);
header('Content type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
//header('Content type:application/vnd.ms-excel');
header('Content disposition: csv;filename="download.xlsx"');
header('Cache-Control: max-age=0');
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');
echo "Test print";
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
?>
<?php
ob_end_flush();
?>
Output:
http://imgur.com/a/5AsWF
Please find what I am missing coz this code gives me garbage output.

Don't print the chart in pdf with phpexcel

Currently I'm making my reports with phpexcel, everythink is ok when I make the report with charts in xlsx;
... $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel2007'); $objWriter->setIncludeCharts(TRUE);
$objWriter->save('php://output');
exit;
and when I do it in html with;
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'HTML');
$objWriter->setIncludeCharts(TRUE);
$objWriter->save('php://output');
But the problem is when I want to create the pdf file my response is a pdf without charts, and yes previously I added the PHPExcel_Settings::PDF_RENDERER_MPDF AND PHPExcel_Settings::CHART_RENDERER_JPGRAPH;
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'PDF');
$objWriter->setIncludeCharts(TRUE);
$objWriter->save('php://output');
May be there is a problem because I save the file in the client browser?

read and write of excel in phpexcel

i accomplished the read of excel with php but the write i cannot, i not know why..
in the file to read, take one column and write in a new file excel and paste there is.. for now only that..
Thank to all..
<?php
require_once "excel/Classes/PHPExcel.php";
require_once "excel/Classes/PHPExcel/IOFactory.php";
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
set_time_limit ( 0 );
ini_set('memory_limit', '-1');
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
?>
<form action="" method="post" enctype="multipart/form-data">
Desea comenzar el proceso ?
<input type="submit" value="Aceptar" name="submit">
</form>
<?php
if(isset($_POST['submit'])){
$objPHPExcel_load = new PHPExcel();
$PHPExcel_save = new PHPExcel();
$PHPExcel_save->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->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");
$PHPExcel_save->setActiveSheetIndex(0)
->setCellValue('A1', 'Cedula');
$PHPExcel_save->getActiveSheet()->setTitle('Simple');
$PHPExcel_save->setActiveSheetIndex(0);
$inputFileName = 'discussdesk.xlsx';
$objPHPExcel_load = PHPExcel_IOFactory::load($inputFileName);
$objWorksheet = $objPHPExcel_load->getActiveSheet();
$cantidad = $objWorksheet->getHighestRow();// tamaño de los registros
$objeto_pegar = $PHPExcel_save->getActiveSheet(0);
echo "cantidad : ".$cantidad;
$prueba = true;
$row = 2;
$column = 1;
for($i = 1;$i <= $cantidad;$i++){
$celda = trim($objWorksheet->getCellByColumnAndRow(7, $row)->getValue());
$PHPExcel_save->setActiveSheetIndex(0)->setCellValueByColumnAndRow(1, $row, $celda);
echo $celda.'<br>';
if(is_null($celda)){
break;
}
$row +=1;
}
$PHPExcel_save->setActiveSheetIndex(0);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="01simple.xlsx"');
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
$objWriter = PHPExcel_IOFactory::createWriter($PHPExcel_save, 'Excel2007');
$objWriter->save('php://output');
}
?>
$PHPExcel_writer = new PHPExcel();
$objReader = PHPExcel_IOFactory::createReader('Excel2007'); // crea el archivo a leer
$PHPExcel_ = $objReader->load('testFile.xlsx'); // load the file
$PHPExcel_->setActiveSheetIndex(0)
->setCellValue('A1', 'field1')
->setCellValue('B1', 'field2')
->setCellValue('C1', 'field3')
->setCellValue('D1', 'field4')
->setCellValue('E1', 'field5')
->setCellValue('F1', 'field6'); // write the first row(tittle)
//$PHPExcel_writer->setActiveSheet()->setTitle('Simple');
$PHPExcel_->setActiveSheetIndex(0);
//
$objPHPExcel_load = new PHPExcel();
$inputFileName = 'discussdesk.xlsx';
$objPHPExcel_load = PHPExcel_IOFactory::load($inputFileName);
$objWorksheet = $objPHPExcel_load->getActiveSheet();
$cantidad = $objWorksheet->getHighestRow();// size of row*/
//echo "count : ".$cantidad;
//$row = 2;
//$column = 1;
//$PHPExcel_writer->getActiveSheet()->setTitle('Simple');
//$PHPExcel_writer->setActiveSheetIndex(0)->setCellValueByColumnAndRow(1, 1, "prueba");
for($i = 1;$i <= 1000;$i++){ ?>
<script> envia_barra(<? echo $i; ?>);
</script>
<?php
/*$celda = trim($objWorksheet->getCellByColumnAndRow(12, $row+3)->getValue());
$data = file_get_contents("youweb?param=".$celda);
set_time_limit(5);
$PHPExcel_->getActiveSheetIndex(0);
if(preg_match('|<td width="180" class="tblbgcolort"><strong>Departamento:</strong></td>\s+<td width="400" class="tblbgcolort">(.*?)</td>|is' , $data , $dep )){
preg_match('|<td width="180" class="tblbgcolort"><strong>Departamento:</strong></td>\s+<td width="400" class="tblbgcolort">(.*?)</td>|is' , $data , $dep );
preg_match('|<td class="tblbgcolor"><strong>Municipio:</strong></td>\s+<td class="tblbgcolor">(.*?)</td>|is' , $data , $mun );
preg_match('%<strong>Puesto:</strong>.+?<td>(.+?)</td>%si',$data,$puesto);
preg_match("%<div style='float:left;'>(.*?)<\/div>%si", $data , $dir );
preg_match('|<td class="tblbgcolor"><strong>Mesa</strong></td>\s+<td class="tblbgcolor">(.*?)</td>|is' , $data , $mes );
$PHPExcel_->setActiveSheetIndex(0)->setCellValueByColumnAndRow(0,$row, $celda);
$PHPExcel_->setActiveSheetIndex(0)->setCellValueByColumnAndRow(1,$row,$dep[1]);
$PHPExcel_->setActiveSheetIndex(0)->setCellValueByColumnAndRow(2,$row,$mun[1]);
$PHPExcel_->setActiveSheetIndex(0)->setCellValueByColumnAndRow(3,$row,$puesto[1]);
$PHPExcel_->setActiveSheetIndex(0)->setCellValueByColumnAndRow(4,$row,$dir[1]);
$PHPExcel_->setActiveSheetIndex(0)->setCellValueByColumnAndRow(5,$row,$mes[1]);
}else{
$PHPExcel_->getActiveSheet()->setCellValueByColumnAndRow(0,$row,$celda);
$PHPExcel_->getActiveSheet()->setCellValueByColumnAndRow(1,$row ,"No hay registro");
}
$row++;
if(is_null($celda)){
break;
}
}
//$PHPExcel_writer->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($PHPExcel_, 'Excel2007');
$objWriter->save('testFile.xlsx');
//$objWriter->save('php://output');
//header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
//header("Content-Disposition: attachment;filename=\"discussdesk.xlsx\"");
//header("Cache-Control: max-age=0");
//$objWriter = PHPExcel_IOFactory::createWriter($PHPExcel_writer, 'Excel2007');
//$objWriter->save('php://output');
exit;

PHPExcel File format or extension is not valid

I'm using phpexcel for export my query in excel file; however after I created file(which is xslx format), I can not open my file in excel. It gives "the file format or extension is not valid. Verify that the file has not been corrupted and that the file extension matches the file format of the file" error. When I open the file in texteditor(mine is npp) I see my php file's css codes and some part of my html codes. My code is like that;
if( ! empty($_POST['export'])){
$query = "SELECT * FROM asd ORDER BY asdf LIMIT 10";
$headings = array('Timestamp', 'h1','h2');
require 'Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->getActiveSheet()->setTitle('List of Users');
$rowNumber = 1;
$col = 'A';
foreach($headings as $heading) {
$objPHPExcel->getActiveSheet()->setCellValue($col.$rowNumber,$heading);
$col++;
}
$rowNumber = 2;
while ($row = mysql_fetch_row($result)) {
$col = 'A';
foreach($row as $cell) {
$objPHPExcel->getActiveSheet()->setCellValue($col.$rowNumber,$cell);
$col++;
}
$rowNumber++;
}
$objPHPExcel->getActiveSheet()->freezePane('A2');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="userList.xlsx"');
header("Content-Transfer-Encoding: binary ");
//ob_end_clean();
//header('Cache-Control: max-age=0');
$objWriter->save('php://output');
exit();
}
I'm stucked please help. Thank you.
As described in the manual.... if anything else is being output to the browser, this will corrupt the output file.
Open the file in a text editor, and look for leading or trailing whitespace characters (spaces, tabs, newlines) or a BOM marker at the beginning of the output, or for any obvious PHP plaintext error messages in the content. These are the most obvious causes of this problem. Once you've identified the spurious characters, check through your script to see where that output is being generated, and remove it.
In your case, that means don't output your css and html.
EDIT
xlsx is the extension for an OfficeOpenXML Excel2007 file, not for a BIFF 8 xls file.... be consistent in your headers (mime type and file extension) and Writer
Either:
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="userList.xls"');
or
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="userList.xlsx"');
Following documentation or comments somewhere I read, I had this:
$objWriter = PHPExcel_IOFactory::createWriter($spreadsheet, 'Excel2007');
header('Content-Type: application/vnd.ms-excel');
// etc
instead of
$objWriter = PHPExcel_IOFactory::createWriter($spreadsheet, 'Excel2007');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
// etc
And that caused Firefox and IE/Edge to append an .xls to the filename and also give the error message when trying to open the file directly instead of downloading it. When downloading the file and opening the spreadsheet though, everything was fine.

PHPExcel output file is empty

I downloaded PHPExcel library but could not use it. I am using one of the examples in the Library but it downloads an empty excel file. Here is my code.
require_once 'PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setTitle("document");
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Hello')
->setCellValue('B1', 'world!');
$objPHPExcel->getActiveSheet()->setTitle('Simple');
$objPHPExcel->setActiveSheetIndex(0);
header("Content-Type: application/vnd.ms-excel");
header('Content-Disposition: attachment;filename="deneme.xls"');
Am i forgetting something here? It is simple but downloaded excel file is empty. Does anyone have an idea?
EDIT:
Solved: I have to add these lines:
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
Add this:
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
die();
You're forgetting to instantiate a writer and then save

Resources