Home > Backend Development > PHP Tutorial > PHPExcel的保存文件问题

PHPExcel的保存文件问题

WBOY
Release: 2016-06-20 12:56:42
Original
1233 people have browsed it

<?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文件的绝对路径?>
Copy after login

这段代码,我用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
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template