How To Get the Range of a Page Using Word Automati

2019-07-16 18:13发布

How do you find the range of page n in Microsoft Word using office automation? There appears to be no getPageRange(n) function and it is unclear how they are divided.

3条回答
爷的心禁止访问
2楼-- · 2019-07-16 18:28

You can use the Matlab OfficeDoc utility for reading/writing Word contents from Matlab: http://www.mathworks.com/matlabcentral/fileexchange/15192-officedoc-readwriteformat-ms-office-docs-xlsdocppt

查看更多
forever°为你锁心
3楼-- · 2019-07-16 18:37

Apologies if I don't have the right context for your question, but from looking at the Office Development docs it seems as though you have to create Range objects that contain what you want. The "Range Object" section of this page says: "The Range object represents a contiguous area in a document, and is defined by a starting character position and an ending character position. You are not limited to a single Range object. You can define multiple Range objects in the same document... [A Range] is not saved with a document and exists only while the code is running."

查看更多
叼着烟拽天下
4楼-- · 2019-07-16 18:45

This is how you do it from VBA, should be fairly trivial to convert to Matlab COM calls.

Public Sub DemoPerPageText()

    Dim i As Integer
    Dim totalPages As Integer
    Dim bmRange As Range

    totalPages = Selection.Information(wdNumberOfPagesInDocument)

    For i = 1 To totalPages
      Set bmRange = ActiveDocument.Bookmarks("\Page").Range
      Debug.Print CStr(i) & " : " & bmRange.Text & vbCrLf
    Next i

End Sub
查看更多
登录 后发表回答