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

发布于 2024-09-29 11:42:56 字数 790 浏览 0 评论 0原文

我正在使用 PHP COM 对象,但我想它在所有其他语言中都是相同的。如何使用 COM / OLE 自动化向 .doc / .docx Microsoft Word 添加水印?

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

谢谢。

I am using PHP COM Object but i guess it is the same in all other languages. How do i add watermark to a .doc / .docx Microsoft Word using COM / OLE Automation?

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

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

○愚か者の日 2024-10-06 11:42:56

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

提示:当您打开文档$word->Documents->Open($abs_filename);时,您将获得对该文档的引用。使用该引用比像现在一样使用 ActiveDocumentDocuments[1] 更好。

In Word start a new macro, and record the steps you need to add a watermark to your document. Then view the generated macro code and translate that to OLE Automation calls in your php script.

TIP: when you open a document $word->Documents->Open($abs_filename); you will get a reference to that document. It is better to work with that reference than working with ActiveDocument and Documents[1] as you do now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文