互操作字 - 删除页面从文档 [英] Interop Word - Delete Page from Document

查看:125
本文介绍了互操作字 - 删除页面从文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是删除使用Word互操作库文档对象特定页面的最简单和最有效的方法是什么?

What is the easiest and most efficient way to delete a specific page from a Document object using the Word Interop Libraries?

我注意到有一个扩展/实现IEnumerable一个页面属性。可以简单地删除该数组中的元素和页面会从文件中删除?

I have noticed there is a Pages property that extends/implements IEnumerable. Can one simply remove the elements in the array and the pages will be removed from the Document?

我也看到了范围和节中的示例,但不看很优雅的使用。

I have also seen the Ranges and Section examples, but the don't look very elegant to use.

感谢。

推荐答案

一个可能的选择是书签整个页面(选择整个页面,请转到工具|插入书签然后键入一个名称)。然后,您可以使用文档对象的书签收藏参考文本并删除它。

One possible option is to bookmark the whole pages (Select the whole page, go to Tools | Insert Bookmark then type in a name). You can then use the Bookmarks collection of the Document object to refer to the text and delete it.

另外,试试C#中的等价code:

Alternatively, try the C# equivalent of this code:

Doc.ActiveWindow.Selection.GoTo wdPage, PageNumber
Doc.Bookmarks("\Page").Range.Text = ""

的第一行移动光标到网页的PageNumber。第二个使用了predefined书签总是指的是网页目前光标在,包括在页面结束时,如果它存在于分页符。

The first line moves the cursor to page "PageNumber". The second one uses a Predefined Bookmark which always refers to the page the cursor is currently on, including the the page break at the end of the page if it exists.

这篇关于互操作字 - 删除页面从文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆