PHPExcel生成的excel文件不起作用(文件格式或扩展名无效) [英] PHPExcel generated excel file not working. (File format or extension is invalid )

查看:1469
本文介绍了PHPExcel生成的excel文件不起作用(文件格式或扩展名无效)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PHPExcel生成的excel文件不起作用(文件格式或扩展名无效)

PHPExcel generated excel file not working. (File format or extension is invalid )

PHPExcel的示例代码在本地PC上成功登录,文件下载到本地,并在Excel 2007中成功打开。
但是在我的服务器上使用相同的代码会给出一个无效的文件,当我打开和修复时,它成功打开。

The example code of PHPExcel exceutes successfully on my local PC , the file gets downloaded to local and is opened in Excel 2007 successfully. But using the same code on my server gives an Invalid file to excel , which when I OPEN AND REPAIR , then it opens successfully.

我不想要使用打开和修复选项,但只能使用打开选项。

I don't want to use the Open and Repair option , but only the Open option.

找不到问题?请帮助。

$objPHPExcel->setActiveSheetIndex(0);


    //for XLSX



    header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');


    header('Content-Disposition: attachment;filename="item_list.xlsx"');

  header('Cache-Control: max-age=0');


   $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');


        $objWriter->save('php://output');


        exit;


推荐答案

您发布的文件有一个空格PHPExcel输出之前的字符...检查您的脚本以查看可能发送到php://输出流的位置。检查您的初始<?php 开始标签之前是否没有空格;特别注意?> <?php 或类似的关闭/打开标签。并且还检查您的脚本中可能包含的任何文件

The file that you've posted has a single space character before the PHPExcel output... check your script to see where this might be sent to the php://output stream. Check that there's no space before your initial <?php opening tag; watch out in particular for ?> <?php or similar closing/opening tags. And also check any files that might be included by your script

这篇关于PHPExcel生成的excel文件不起作用(文件格式或扩展名无效)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆