当前位置:首页 > Windows程序 > 正文

方式二:通过vba --因为vba需要打开word

2024-03-31 Windows程序

方法一:通过openxml 从xml布局里获得
不成行。原因如下
A footer is not on a page and a page number in a footer is a field that potentially identifies with multiple pages. In a Word document file, there are no pages. Pages are set as a part of the printing process.
It is possible with the file open in Word to identify a page number using vba but it is not part of the xml.
翻译一下,页脚并不存在于页面上,页脚上的页码是一个有可能颠末多个页才华确定的域。在一个word文档中,,并没有页,页被认为是一个word页面绘制过程。
使用vba用word打开文档可以确定页码,但页码并不存在于xml上。

下面这种情况可以从xml布局中获得一部分页码。即word中存在目录。但只能获得纲要标题地址页。并不能任意指定段落。而且并不保证准确,因为默认情况下目录并不自动更新。
虽然页码在xml布局中不存在,但是目录上纲要标题对应的页是硬编码在xml布局里的。

方法二:通过vba --因为vba需要打开word,所以是可以获得页码的

/// <summary> /// 得到Paragraph地址页码 /// </summary> /// <param></param> /// <returns></returns> public static int GetPageNumberOfParagraph(Paragraph pa) { return GetPageNumberOfRange(pa.Range); } private static int GetPageNumberOfRange(Range range) { return (int)range.get_Information(WdInformation.wdActiveEndPageNumber); }

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/34031.html

Jm-杰米博客Jamie
草根站长的技术交流乐园!IT不会不要紧快来好好学习吧!
  • 20786文章总数
  • 7494587访问次数
  • 建站天数
  • 友情链接