2012-07-10 90 views
0

我试图根据PHPWord example的示例示例生成一个单词模板。但是没有生成单词模板或者无法成功显示页面。我已经过滤了示例代码,只添加了hello world的一个部分!配置和运行PHPWord

Code: 
<?php 
    require_once 'PHPWord.php'; 
    $PHPWord = new PHPWord(); 
    $section = $PHPWord->createSection(); 
    $section->addText('Hello world!'); 
    header("Cache-Control: public"); 
    header("Content-Description: File Transfer"); 
    header("Content-Disposition: attachment; filename=helloWorld.docx"); 
    header("Content-Type: application/docx"); 
    header("Content-Transfer-Encoding: binary"); 
    $objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007'); 
    $objWriter->save('helloWorld.docx'); 
    ?> 

请注意,如果我使用objwriter->保存helloworld.docx。它会自动进入我的网络服务器吗?或临时文件夹?

谢谢!

+0

文件将在你的脚本运行 – 2012-07-10 13:59:15

+0

确定当前工作目录中创建。任何想法为什么我的网页不能加载?它会显示一个下载图标? – JLearner 2012-07-10 14:00:23

+0

不,它不会显示下载图标,也没有任何输出到代码中的浏览器(除了标题)。这将简单地执行并将文件写入服务器的磁盘......标题是毫无意义的。如果要将输出发送到浏览器,请使用“按原样”标题,但将save()调用中的文件名更改为php://输出 – 2012-07-10 14:09:03

回答

0

如果你希望你的网页来强制下载所生成的文档,只需使用以下命令:

$PHPWord->save('helloWorld.docx', 'Word2007', true);