$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);
它创建了一段奇怪的字符
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"[�97pGWg-�$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��
它适用于localhost,但是一旦我将它托管到托管服务器就会出现问题。
答案 0 :(得分:1)
如果有帮助,我在使用Excel2007 Writer时通常发送的标题是:
// 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