L'exécution de header('Content-Type: application/vnd.ms-excel'); dans mon fichier php ne semble avoir aucun effet. Le fichier généré est toujours un fichier HTML. Que se passe-t-il ?
phpcn_u13074
phpcn_u13074 2017-08-02 21:09:23
0
2
1435
phpcn_u13074
phpcn_u13074

répondre à tous(2)
phpcn_u13074
这是我的代码
<?php
$dir=dirname(_FILE_);
require $dir."/PHPExcel/PHPExcel.php";
$objPHPExcel=new PHPExcel();
$objSheet=$objPHPExcel->getActiveSheet();
$objSheet->setTitle("demo");
//$objSheet->setCellValue("A1","可可")->setCellValue("b1","蛋蛋");
$array=array(
array("姓名","年龄"),
array("大可","58")
);
$objSheet->fromArray($array);
$objWriter=PHPExcel_IOFactory::createWriter($objPHPExcel,"Excel5");
$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="ch3.xls"');
header('Cache-Control: max-age=0');
$objWriter->save("php://output");

?> 但是产生的xls文件确实这个东西:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>��ࡱ�;��	��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������	

����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Oh��+'��0�@Hh��
���Untitled SpreadsheetUnknown CreatorUnknown Creator@���@�@���@�	�
��B�=�%r8X"1��Calibri��� �	��� �	��� �	��� �	��� �	��� �	��� �	��� �	��� �	��� �	��� �	��� �	��� �	��� �	��� �	� �	�����8�������������������������������3f������ff���f����������������������������������̙��̙3f�3���������fff����3f3�f333�3�3f33�333�demo��g����Y
Tt^��'Y�S
	�
��*+������&ffffff�?'ffffff�?(�?)�?�"dXX333333�?333333�?U}$	}$	�
�
�
M@>�@d��dgg�����
����՜.��+,��0�HPX`hp
x��
WorksheetFeuilles de calculRoot Entry��������	�F���@����@��SummaryInformation(����	�F�Workbook������������	�F�DocumentSummaryInformation8������������	�F��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� 
</body>
</html>


Ty80

J'ai testé qu'il peut être téléchargé. Peut-être que votre navigateur l'ouvre directement par défaut. Vous pouvez essayer d'utiliser un autre navigateur.

Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!