简体   繁体   English

通过PHP在MS Word文件中添加文本

[英]Adding texts in a ms word file through PHP

I have a ms word file with few texts, is there any way to add few texts in it using php code. 我有一个MS Word文件,只有很少的文本,有什么方法可以使用php代码在其中添加一些文本。

for instance, I have a word file and it has text like 'My name is.....', i would like to add one name in the dotted place using php code. 例如,我有一个word文件,它的文本如“我的名字是.....”,我想使用php代码在点缀位置添加一个名字。 在此处输入图片说明

You would need to use Libraries like PHPWORD .It provides a set of classes to write to and read from different document file formats. 您将需要使用像PHPWORD这样的库。它提供了一组类来读写不同的文档文件格式。 You can also use phpLiveDocx which is a Zend Framework component and can read and write DOC and DOCX files in PHP on Linux, Windows and Mac. 您还可以使用phpLiveDocx ,它是Zend Framework的组件,可以在Linux,Windows和Mac上的PHP中读写DOC和DOCX文件。 A sample code to do this with PHP COM 使用PHP COM执行此操作的示例代码

<?php 
// Create COM instance to word 

       function clsMSWord($Visible = false) 
   { 
       $this->handle = new COM("word.application") or die("Unable to instanciate Word"); 
       $this->handle->Visible = $Visible; 
   } 

function WriteHyperlink($Bookmark,$Path,$Text) 
   { 
           $objBookmark = $this->handle->ActiveDocument->Bookmarks($Bookmark); 
           $range = $objBookmark->Range; 
           $objHyperlink = $this->handle->ActiveDocument->Hyperlinks; 
           $objHyperlink->add($range,$Path,"","",$Text); 

   } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM