修改Word文档属性

时间:2010-12-27 09:58:58

标签: php

我想发送一个Microsoft Word文档。但在发送之前,我想在使用PHP发送之前修改其属性,如(文档标题,主题,作者,团队,经理,公司等)。

我不能使用COM,因为我刚刚得知这个脚本运行的服务器没有ms office也不允许安装它...所以请给我一些其他解决方案。

由于

3 个答案:

答案 0 :(得分:1)

您正在寻找的是在PHP中使用Component Object Model,这是另一个tutorial

修改 用于打开新MS Word文档的示例代码:

$word = new COM("word.application") or die ("something went wrong!!");
//open new word document
$word->Documents->Add();
//type text into the document
$word->Selection->TypeText("this is some sample text in the document");
//save document
$word->Documents[1]->SaveAs("newWordDocument.doc");
//close word
$word->Quit();
//free object resources
$word->Release();
$word = null;

答案 1 :(得分:0)

我正在尝试打开COM,但它只是继续处理。

  

$ word = new COM(“word.application”)或   死(“无法实例化应用程序   对象“);

     

$ DocumentPath = $ NEWNAME; //打开虚空文件

     

$ wordDocument = $ word-> Documents-> Open($ DocumentPath);   >

     

//清理

     

$ wordDocument = null;   $字处理>退出();

     

$ word = null;

如果我添加这一行然后它继续处理..如果我通过它我无法打开文件...我做错了什么

  

$字处理>文件─>打开($ DocumentPath);

答案 2 :(得分:0)

因为问题在于服务器环境 - 我建议使用OpenOffice和组件phpdocwriter。它能够加载Microsoft Office文档并操纵它们的信息。

希望这有帮助!

相关问题