加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何找到Word段落的页码?

发布时间:2020-12-15 18:01:41 所属栏目:百科 来源:网络整理
导读:我试图解析一个Word文档,我正在寻找的信息应该位于第一页.有没有办法得到一个段落的页码? foreach (Word.Paragraph p in document.Paragraphs){ // pageNo = ..... // if(pageNo == 1 p.Range.Text.StartsWith("This")) { // /* do some processing with th
我试图解析一个Word文档,我正在寻找的信息应该位于第一页.有没有办法得到一个段落的页码?
foreach (Word.Paragraph p in document.Paragraphs)
{
    // pageNo = .....
    // if(pageNo == 1 && p.Range.Text.StartsWith("This")) { 
    //     /* do some processing with the paragraph */ 
    // }
}

解决方法

从这个帖子 VSTO 2007: how do I determine the page and paragraph number of a Range?我可以看到你可以得到一个范围的页数
/// <summary>
    /// Determines the pagenumber of a range.
    /// </summary>
    /// <param name="range">The range to be located.</param>
    /// <returns></returns>
    private static int GetPageNumberOfRange(Word.Range range)
    {
        return (int)range.get_Information(Word.WdInformation.wdActiveEndPageNumber);
    }

从这个帖子,how to detect Empty paragraph in Word Document using Microsoft.Office.Interop.Word in C#4.0?我确定你可以找到范围从段落!

for each p in Doc.Content.Paragraphs
    if (p.Range.End - p.Range.Start) > 1 then (The paragraph is empty)
Next

你应该把你的解决方案结合在一起,我敢打赌!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读