phpExcel导出excel打不开问题

来源:互联网 发布:网络伤感歌曲打包下载 编辑:程序博客网 时间:2024/04/30 23:46

关于phpExcel导出excel之后打开不了的问题

情况说明:

我相信很多人用过phpExcel这个类库都会遇到的一个问题就是,导出excel表格文件后(xls或xlsx文件),打开这个文件既然显示这里写图片描述
然后网上也很多解决办法,主要看大家的情况而选择用哪用方法。

  • 网上主要的问题以及解决的方法:

    文件带有UTF-8 BOM:这种情况只要把签名给删掉就可以了,将文件改成不带BOM签名。


  • 我就说一下我这次的问题所在,希望大家遇到这种情况时候也可以帮到各位

    我这次的情况是这样:我文件没有带UTF-8 BOM,而且在本地测试的时候也没有问题,但是放到服务器上就出现导出EXCEL之后打不开的问题。


  • 然后我就用编译器打开了一个不能开打的excel文件:

    <br />
    <b>Warning</b>: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in <b>C:\wtf\enroll_beta\lib\phpExcel\Classes\PHPExcel\Writer\Excel2007\DocProps.php</b> on line <b>172</b><br />
    <br />
    <b>Warning</b>: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in <b>C:\wtf\enroll_beta\lib\phpExcel\Classes\PHPExcel\Writer\Excel2007\DocProps.php</b> on line <b>178</b><br />
    PK

  • 然而真正能打开的excel文件里面的代码是这样的额:

504b 0304 1400 0000 0800 3cab 0249 479244b2 5801 0000 f004 0000 1300 0000 5b436f6e 7465 6e74 5f54 7970 6573 5d2e 786d6cad 944d 4ec3 3010 85f7 9c22 f216 256e5920 849a 7641 6109 9528 0730 f6a4 b1ead896 67fa 777b 2669 0b08 8940 d56e 6245f67b dff8 79ec d164 dbb8 6c0d 096d f0a51816 0391 81d7 c158 bf28 c5db fc29 bf131992 f246 b9e0 a114 3b40 3119 5f8d e6bb0898 b1d8 6329 6aa2 782f 25ea 1a1a 854588e0 79a6 0aa9 51c4 bf69 21a3 d24b b5007933 18dc 4a1d 3c81 a79c 5a0f 311e bd303f59 03d9 4c25 7a56 0d63 e4d6 4962 37d87f87 05fb 89ec 612f 6cd9 a550 313a ab1571e1 72ed cd0f 6a1e aaca 6a30 41af 1a96149d cd75 eb22 7f05 22ed 1ce0 d928 8c09(太多就不全部打印出来了)
  • 我的猜想是因为服务器时间区域跟phpExcel函数库脸面的时间区域选用不一致,然后报了个warming。虽然warming不影响函数的执行,但是php导出excel文件,是header出来的。这个warning一出来,就把warning的信息都导入到excel文件里面了,自然WPS或者office软件就识别不了里面的代码,自然就无法打开不了文件。

  • 我的解决办法:

    既然是因为warning的影响,那我就把它屏蔽掉吧,然后我就函数第一行加了这行代码:
    error_reporting(0);
    这行代码的作用就是把warning,error等等的信息不显示出来。
    最后执行,导出来的excel文件就可以顺利打开了。


博主新手上路,小弟要学习的东西还多,如有解释得不到位,概念解释错误的,请各位大神直接点出,感谢!!

0 0