0

私はPHP COM Objectを使用していますが、他のすべての言語でも同じだと思います。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);

ありがとう。

4

1 に答える 1

1

Word で新しいマクロを開始し、ドキュメントに透かしを追加するために必要な手順を記録します。次に、生成されたマクロ コードを表示し、それを php スクリプトの OLE オートメーション呼び出しに変換します。

ヒント: ドキュメントを開くと、$word->Documents->Open($abs_filename);そのドキュメントへの参照が表示されます。ActiveDocument現在のようにandを使用するよりも、その参照を使用する方が適切Documents[1]です。

于 2010-11-09T08:13:36.400 に答える