我有一个Word文档,想要获取文档中任意段落的页码。我意识到段落可以跨页面,所以我实际上需要询问段落的开头(或结尾)。像这样的伪代码:
set the_page_number to page number of character 1 of paragraph 1 of my_document
我无法弄清楚你如何将范围对象与任何有关其渲染的信息联系起来,并且我正式感到困惑。
有谁知道正确的方法?
答案 0 :(得分:3)
我刚刚在C#中找到了关于处理此问题的问题:How do I find the page number for a Word Paragraph?
在答案中我找到了对range.get_Information(Word.WdInformation.wdActiveEndPageNumber)
事实证明,在applescript字典中有一个get range information
命令,所以你可以这样做:
set the_range to text object of character 1 of paragraph 123 of the_document
set page_number to get range information the_range information type active end adjusted page number
这将获得将要打印的页码(例如,如果您将文档设置为从第42页开始,这将产生您期望的数字)。或者,您可以在不进行调整的情况下获取数字,即您的文档页面编号设置为从42开始,但您希望页码编号好像编号从1开始。
set the_range to text object of character 1 of paragraph 456 of the_document
set page_number to get range information the_range information type active end page number
呼。