首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Word OLE自动化水印添加到MS-Office COM对象中

Word OLE自动化水印添加到MS-Office COM对象中
EN

Stack Overflow用户
提问于 2010-10-30 19:38:41
回答 1查看 1.7K关注 0票数 0

我使用的是PHP COM对象,但我猜它在所有其他语言中都是一样的。如何使用COM / OLE自动化将水印添加到.doc / .docx Microsoft Word?

代码语言:javascript
复制
    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);

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2010-11-09 16:13:36

在Word中启动新宏,并记录向文档添加水印所需的步骤。然后查看生成的宏代码,并将其转换为php脚本中的OLE自动化调用。

提示:当您打开一个文档$word->Documents->Open($abs_filename);时,您将看到对该文档的引用。最好使用该引用,而不是像现在这样使用ActiveDocumentDocuments[1]

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4058510

复制
相关文章

相似问题

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