首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用php编辑.doc或.docx文件

使用php编辑.doc或.docx文件
EN

Stack Overflow用户
提问于 2010-07-30 14:12:40
回答 5查看 29.3K关注 0票数 15

我必须修改上传的.doc或.docx文件在php。我用谷歌搜索过,但我只找到了如何阅读它。我希望word文件是这样的,并在运行时将文本放在该MS Word文件的底部。这是怎么可能的,任何人都知道,请回复或给我示例脚本。

谢谢,

EN

回答 5

Stack Overflow用户

发布于 2010-08-30 01:37:30

我是PHPWord的开发者。您可以使用PHPWord_Template类打开现有的DOCX文件,然后用您的单个文本替换某些文本标记。

或者,您可以打开扩展名为ZipArchive的DOCX文件,然后读/写每个xml文件(document.xml、header.xml、footer.xml等)。你想要的。这个方法就是PHPWord_Template类。;)

票数 17
EN

Stack Overflow用户

发布于 2010-07-30 15:31:14

您可以使用PHPWord

票数 9
EN

Stack Overflow用户

发布于 2017-11-04 14:35:37

我有同样的要求编辑.doc.docx文件使用php和我找到了解决方案。我在上面写了一篇文章::http://www.onlinecode.org/update-docx-file-using-php/

代码语言:javascript
运行
复制
if($zip_val->open($full_path) == true)
{
    // In the Open XML Wordprocessing format content is stored.
    // In the document.xml file located in the word directory.

    $key_file_name = 'word/document.xml';
    $message = $zip_val->getFromName($key_file_name);               

    $timestamp = date('d-M-Y H:i:s');

    // this data Replace the placeholders with actual values
    $message = str_replace("client_full_name",      "onlinecode org",       $message);
    $message = str_replace("client_email_address",  "ingo@onlinecode.org",  $message);
    $message = str_replace("date_today",            $timestamp,         $message);      
    $message = str_replace("client_website",        "www.onlinecode.org",   $message);      
    $message = str_replace("client_mobile_number",  "+1999999999",          $message);

    //Replace the content with the new content created above.
    $zip_val->addFromString($key_file_name, $message);
    $zip_val->close();
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3369061

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档