一种最简单的导出excel方式和导出word.这种导出excel导出后因为本质是html页面所以无法无法导入,如需要导入,可使用类phpexcel.
1:导出word(第一行的<?php 之前不允许有空格和换行)
<?php
header("Content-Type:application/msword");
header("Content-Disposition:attachment;filename=1.doc");
header("Pragma:no-cache");
header("Expires:0");
echo 1;
第二行指定导出的word名称 ,例如:1.doc
2:导出excel
<?php
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=测试.xls");
header('Pragma:no-cache');
header('Expires:0');
如果导出乱码在header下加如下代码即可(根据需要修改自己的编码类型charset=utf-8),亲测有效
echo '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><xml><w:WordDocument><w:View></w:View></xml></head>';