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

时间:2022-10-26 19:54:37

I have to modify the uploaded .doc or .docx file in php. I googled but i only found how to read that. I want the word file as it is and put text at the bottom of that MS Word file at run time. How is this possible anyone know please reply or give me example script.

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

Thanks,

4 个解决方案

#1


17  

I'm the developer of PHPWord. You can use the PHPWord_Template Class to open an existing DOCX File and then replace some text marks with your individual text.

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

Alternatively you can open the DOCX file with the ZipArchive extension and then read/write every xml File (document.xml, header.xml, footer.xml, ...) you want. This method is nothing else than the PHPWord_Template class. ;)

或者,您可以使用ZipArchive扩展打开DOCX文件,然后读取/写入您想要的每个xml文件(document.xml,header.xml,footer.xml,...)。这个方法只不过是PHPWord_Template类。 ;)

#2


9  

You can use PHPWord.

你可以使用PHPWord。

#3


1  

I have same requirement for Edit .doc or .docx file using php and i have find solution for it. And i have write post on It :: http://www.onlinecode.org/update-docx-file-using-php/

我对使用php的Edit .doc或.docx文件有相同的要求,我找到了它的解决方案。我在It上写了帖子:: http://www.onlinecode.org/update-docx-file-using-php/

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();
}

#4


0  

Try having a look at http://www.tinybutstrong.com/ as it can create and edit Word documents, we use it in a mail merge style for generating invoices in doc and pdf.

尝试查看http://www.tinybutstrong.com/,因为它可以创建和编辑Word文档,我们以邮件合并方式使用它来生成doc和pdf中的发票。

#1


17  

I'm the developer of PHPWord. You can use the PHPWord_Template Class to open an existing DOCX File and then replace some text marks with your individual text.

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

Alternatively you can open the DOCX file with the ZipArchive extension and then read/write every xml File (document.xml, header.xml, footer.xml, ...) you want. This method is nothing else than the PHPWord_Template class. ;)

或者,您可以使用ZipArchive扩展打开DOCX文件,然后读取/写入您想要的每个xml文件(document.xml,header.xml,footer.xml,...)。这个方法只不过是PHPWord_Template类。 ;)

#2


9  

You can use PHPWord.

你可以使用PHPWord。

#3


1  

I have same requirement for Edit .doc or .docx file using php and i have find solution for it. And i have write post on It :: http://www.onlinecode.org/update-docx-file-using-php/

我对使用php的Edit .doc或.docx文件有相同的要求,我找到了它的解决方案。我在It上写了帖子:: http://www.onlinecode.org/update-docx-file-using-php/

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();
}

#4


0  

Try having a look at http://www.tinybutstrong.com/ as it can create and edit Word documents, we use it in a mail merge style for generating invoices in doc and pdf.

尝试查看http://www.tinybutstrong.com/,因为它可以创建和编辑Word文档,我们以邮件合并方式使用它来生成doc和pdf中的发票。