zoukankan      html  css  js  c++  java
  • C# 获得word中某一段落所在页的页码

    方式一:通过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 name="pa"></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);
            }
  • 相关阅读:
    Mybatis中javaType和jdbcType对应关系
    spy日志
    mybatis批量插入和更新
    js打印方案
    js弹窗,父子窗口调用
    extjs4.1
    oracle开启远程连接访问
    javaweb打印
    Leetcode 392.判断子序列
    Leetcode 391.完美矩形
  • 原文地址:https://www.cnblogs.com/xushy/p/8650186.html
Copyright © 2011-2022 走看看