2010-10-30 95 views
0

我正在使用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); 

謝謝。

回答

1

在Word中啓動一個新的宏,並記錄您需要爲文檔添加水印的步驟。然後查看生成的宏代碼並將其轉換爲您的PHP腳本中的OLE自動化調用。

提示:當您打開文檔$word->Documents->Open($abs_filename);時,您將獲得對該文檔的引用。像現在這樣,使用該參考文件比使用ActiveDocumentDocuments[1]更好。