2011-08-17 12 views
10

मैं एक वर्ड डॉक्यूमेंट पार्स करने की कोशिश कर रहा हूं और जो जानकारी मैं ढूंढ रहा हूं वह केवल पहले पेज पर ही होनी चाहिए। क्या अनुच्छेद के लिए पृष्ठ संख्या प्राप्त करने का कोई तरीका है?मुझे वर्ड पैराग्राफ के लिए पेज नंबर कैसे मिलेगा?

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

उत्तर

16

इस पोस्ट 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 

आपके पास दोनों समाधानों का संयोजन करने का आपका समाधान होना चाहिए, मैं शर्त लगाता हूं!

4
foreach (Word.Paragraph p in document.Paragraphs) 
{ 
    int page = p.Range.Information[Word.WdInformation.wdActiveEndAdjustedPageNumber]; 
    Console.WriteLine(p.Range.Text + " is on page " + page); 
} 

ऐसा कुछ हो सकता है जो आप खोज रहे हैं। WdActiveEndPageNumber और wdActiveEndAdjustedPageNumber के बीच के अंतर पर पढ़ें, यह देखने के लिए कि आपकी आवश्यकता के अनुरूप कौन सा है।

संबंधित मुद्दे