>  기사  >  백엔드 개발  >  PHPExcel的保存文件问题

PHPExcel的保存文件问题

WBOY
WBOY원래의
2016-06-20 12:56:421221검색

<?phperror_reporting(E_ALL);set_include_path(get_include_path().PATH_SEPARATOR."./php/Classes/");require_once("PHPExcel.php");require_once("PHPExcel/IOFactory.php");$objPHPExcel = new PHPExcel();$objPHPExcel->getProperties()->setCreator("Maarten Balliauw");$objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw");$objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");$objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");$objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.");$objPHPExcel->getProperties()->setKeywords("office 2007 openxml php");$objPHPExcel->getProperties()->setCategory("Test result file");$objPHPExcel->setActiveSheetIndex(0);$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Hello1');$objPHPExcel->getActiveSheet()->setCellValue('B1', 'world2');$objPHPExcel->getActiveSheet()->setCellValue('C1', 'Hello3');$objPHPExcel->getActiveSheet()->setCellValue('D1', 'world4');$objPHPExcel->getActiveSheet()->setTitle('sheet01');$objPHPExcel->setActiveSheetIndex(0);$phpexcel = PHPExcel_IOFactory::load("phonelist.xls");$sheet = clone $phpexcel->getActiveSheet();$objPHPExcel->addExternalSheet($sheet);$objPHPExcel->removeSheetByIndex(0);$objPHPExcel->getActiveSheet()->removeRow(3);$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');$objWriter->save(str_replace('.php', '.xlsx', __FILE__));// __FILE__ =>  excel文件的绝对路径?>

这段代码,我用php命令执行,可以创建一个后缀位xlsx的文件.但是如果我把这段代码放在带html标签的文件中然后用火狐浏览器打开.就无法创建,这是什么原因啊.修改过后的文件内容大致如下:


<br>   号码管理系统 <br>



">
  
姓名 :  
  



error_reporting(E_ALL);

set_include_path(get_include_path().PATH_SEPARATOR."./php/Classes");
require_once("PHPExcel.php");
require_once("PHPExcel/IOFactory.php");

$filename = "phonelist.xls";

if (!empty($_POST["insert"]))
{
    $objPHPExcel = new PHPExcel();
    $objPHPExcel->getProperties()->setCreator("Maarten Balliauw");
    $objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw");
    $objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");
    $objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");
    $objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.");
    $objPHPExcel->getProperties()->setKeywords("office 2007 openxml php");
    $objPHPExcel->getProperties()->setCategory("Test result file");
    $objPHPExcel->setActiveSheetIndex(0);
    $objPHPExcel->getActiveSheet()->setCellValue('A1', 'Hello1');
    $objPHPExcel->getActiveSheet()->setCellValue('B1', 'world2');
    $objPHPExcel->getActiveSheet()->setCellValue('C1', 'Hello3');
    $objPHPExcel->getActiveSheet()->setCellValue('D1', 'world4');
    $objPHPExcel->getActiveSheet()->setTitle('sheet01');
    $objPHPExcel->setActiveSheetIndex(0);

    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel2007");
    $objWriter->save(str_replace('.php', '.xlsx', __FILE__));
}

?>




回复讨论(解决方案)

为什么要用 form包住代码?
把放到php代码前面看看。

为什么要用 form包住代码?
把放到php代码前面看看。


正愁找不到我的帖子呢.郁闷,csdn自己发的帖子都找不到.问题解决了.是权限问题.
http://blog.csdn.net/cp3alai/article/details/45665283
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.