Home  >  Article  >  Backend Development  >  php导出word文档与excel电子表格的简单示例代码_PHP

php导出word文档与excel电子表格的简单示例代码_PHP

WBOY
WBOYOriginal
2016-06-01 11:55:17763browse
生成word的代码:
复制代码 代码如下:
 header("Content-type: application/octet-stream");
 header("Accept-Ranges: bytes");
 header('Content-type: application/doc');
 header('Content-Disposition: attachment; filename="测试.doc"');

生成excel的代码 :
复制代码 代码如下:
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
Header("Content-type:application/vnd.ms-excel");
Header("Content-Disposition:attachment;filename="测试.xls"');

但是导的过程中也会遇到很多问题,比如说导出excel,某列导出的是身份证号的话,打开excel文件以后会发现,身份证号自动采用科学计数法,无论如何修改该列属性,都无法实现自己的要求。网上有人说,先把该列属性改为文本以后,再输入就没有问题,实际操作excel确实如此,但是,php程序导出就无法做到了。也有人说,在身份证号前加单引号,试过也不行,最后在导出的身份证号数据前加空格问题解决,空格是html代码的空格.问题解决。
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn