Word OLE自动化水印添加在MS-Office COM对象
问题描述:
我正在使用PHP COM对象,但我想它在所有其他语言中都是一样的。如何使用COM/OLE自动化为.doc/.docx Microsoft Word添加水印?Word OLE自动化水印添加在MS-Office COM对象
try
{
$word = new COM("word.application") //$word = new COM("C:\\x.docx");
or die(error::asString("couldnt create an instance of word", 20100408.01812, true));
//bring word to the front
$word->Visible = 1;
//open a word document
$word->Documents->Open($abs_filename);
$range = $word->ActiveDocument->Content();
$this->text = iconv('CP1255', 'UTF-8', $range->Text);
//save the document as html
// format: 0 - same?, 1 - doc?, 2 - text, 4 - text other encoding, 5 - ?, 6 - rtf , 8 - html
$word->Documents[1]->SaveAs($result_file_name, 8);
谢谢。
答
在Word中启动一个新的宏,并记录您需要为文档添加水印的步骤。然后查看生成的宏代码并将其转换为您的PHP脚本中的OLE自动化调用。
提示:当您打开文档$word->Documents->Open($abs_filename);
时,您将获得对该文档的引用。像现在这样,使用该参考文件比使用ActiveDocument
和Documents[1]
更好。