【问题标题】:Displaying a preview of a word document using officeapps API and PHP output使用 officeapps API 和 PHP 输出显示 Word 文档的预览
【发布时间】:2021-03-07 05:06:34
【问题描述】:

我正在尝试使用 Office 的实时视图显示嵌入 Word 文档的预览。我不想使用保存的 .docx 文件。我正在使用 PHPWORD 库使用它的 templateProccessing 类创建文档。

当我指的是保存文档的路径而不是 php 输出时,一切正常。

我目前拥有的是

HTML

<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=https://homeurl.com/panel/export?code=MYaM14lMfqm8NFYxpO67&id=43' ' width='1366px' height='623px' frameborder='0'></iframe>

在服务器端我有:

PHP

header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=" . $params['document_name']. ".docx");
header("Content-Transfer-Encoding: binary");
$templateProcessor->saveAs("php://output");

iframe 预览显示无法读取文件。

我认为这与标题信息有关,但我还没有找到解决方案。

【问题讨论】:

    标签: php phpword


    【解决方案1】:

    我发现如果文件 url 不包含文件名和扩展名,它就不起作用,就像你的情况一样。如果你修改你的网址,它会以某种方式工作:

    <iframe src='https://view.officeapps.live.com/op/embed.aspx?src=https://homeurl.com/panel/export/file.docx?code=MYaM14lMfqm8NFYxpO67&id=43' ' width='1366px' height='623px' frameborder='0'></iframe>
    

    找不到任何文档来确定是否有更好的方法使其工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多