如何找到Word段落的页码? [英] How do I find the page number for a Word Paragraph?

查看:271
本文介绍了如何找到Word段落的页码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解析Word文档,而我正在寻找的信息应仅位于第一页上.有什么方法可以获取段落的页码吗?

I am trying to parse a Word document and the information I am looking for should be located on the first page only. Is there any way to get the page number for a paragraph?

foreach (Word.Paragraph p in document.Paragraphs)
{
    // pageNo = .....
    // if(pageNo == 1 && p.Range.Text.StartsWith("This")) { 
    //     /* do some processing with the paragraph */ 
    // }
}

推荐答案

此帖子

From this post VSTO 2007: how do I determine the page and paragraph number of a Range? i could see you could get Page number form 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);
    }

在这篇文章中,

And from this post, how to detect Empty paragraph in Word Document using Microsoft.Office.Interop.Word in C#4.0? i am sure u could find the Range from the paragraph!

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

我敢打赌,您应该结合两个答案来解决您的问题!

you should have your solution combining both the answers, i bet!

这篇关于如何找到Word段落的页码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆