How To Get the Range of a Page Using Word Automation

北战南征 提交于 2019-12-10 22:58:16

问题


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.


回答1:


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



回答2:


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




回答3:


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."



来源:https://stackoverflow.com/questions/1076348/how-to-get-the-range-of-a-page-using-word-automation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!