Word OLE 自动化 - 删除首页并操作页眉和页脚
我正在使用 PHP 来启动 Word Automation 并操作 Word 文档,但我想它可以用所有其他语言来完成。我需要做的很简单,我需要删除第一页并添加页眉和页脚。
这是我的代码:
$word = new COM('word.applicantion');
$word->Documents->Open('xxx.docx');
$word->Documents[1]->SaveAs($result_file_name, 12);
有示例吗?
I am using PHP to start Word Automation and manipulate word documents, but i guess it can be done in all any other language. What i need to do is quite simple, i need to remove the first page and add header and footer.
Here is my code:
$word = new COM('word.applicantion');
$word->Documents->Open('xxx.docx');
$word->Documents[1]->SaveAs($result_file_name, 12);
Any samples?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是您在 VBA 中可以实现的方法。这可能可以相当简单地移植到 PHP。
请注意
...InlineShapes.AddPicture
- 您有责任确保图片尺寸正确。如果您想对此进行更多控制,您可以使用.Footers(1).Shapes.AddPicture
来代替,因为这样您就可以设置宽度/高度、顶部/左侧等。This is the way you could do it in VBA. This can likely be ported to PHP fairly simply.
Note on the
...InlineShapes.AddPicture
- the onus would be on you to ensure the picture is the right size. If you want more control over this, you would use.Footers(1).Shapes.AddPicture
instead as that let's you set the width/height, top/left, etc.尝试
{
$word = new COM("word.application") //$word = new COM("C:\x.docx");
或死(“无法创建单词的实例”);
try
{
$word = new COM("word.application") //$word = new COM("C:\x.docx");
or die("couldnt create an instance of word");