Interop Word - remove page from document

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

I noticed that there is a Pages property that extends / implements IEnumerable. Is it possible to simply delete elements in an array and the pages will be deleted from the document?

I also saw examples of Ranges and Section, but they do not look very elegant to use.

Thank.

+3
source share
2 answers

, ( , "", " ", ). Document, .

# :

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

"PageNumber". , , , , .

+4

, , .

. Word, ; , - , , (, ). Pages Pane (, , Application.ActiveWindow.ActivePane), . , Page , ( ) , .

(), , , , . , , ( , , ). , :

object missing = Type.Missing;
foreach (Microsoft.Office.Interop.Word.Section section in doc.Sections) {
    if (/* some criteria */) {
        section.Range.Delete(ref missing, ref missing);
        break;
    }
}
+3

Source: https://habr.com/ru/post/1765680/


All Articles