在 MS-Office COM 对象中添加 Word OLE 自动化水印
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Word 中启动一个新宏,并记录向文档添加水印所需的步骤。然后查看生成的宏代码并将其转换为 php 脚本中的 OLE 自动化调用。
提示:当您打开文档
$word->Documents->Open($abs_filename);
时,您将获得对该文档的引用。使用该引用比像现在一样使用ActiveDocument
和Documents[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 withActiveDocument
andDocuments[1]
as you do now.