0

我正在尝试根据PHPWord 示例的示例示例生成一个单词模板。但是没有生成word模板或无法成功显示页面。我已经过滤掉了示例代码,只添加了一段hello world!

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。它会自动在我的网络服务器中吗?还是临时文件夹?

谢谢!

4

1 回答 1

0

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

$PHPWord->save('helloWorld.docx', 'Word2007', true);
于 2017-07-04T14:11:19.047 回答