locked
MS Word Application RRS feed

  • Question

  • Hi

     

    I am using the word in my application. I want to know the characters count and lines count I am already satisfied with the characters count by the  word count feature of MS Word, but still I have some issue with the line count. I need something more than the MS word giving in the case of line count by its word count feature. Word counting the non character line also as one line, how can I avoid that none character lines from the gross line count? Please give me you valuable replay for my this problem.

     

    Thanks in advance

    Wednesday, May 13, 2009 1:11 PM

Answers

  • Hi again!

    You can use the ComputeStatistics() method to count the lines for each paragraph in the document:


    int totalLineCount = 0;
    Word._Document document = CurrentDocument;

    foreach (Word.Paragraph paragraph in document.Paragraphs)
    {
        if (String.Empty != paragraph.Range.Text.Trim())
        {
            totalLineCount += paragraph.Range.ComputeStatistics(Word.WdStatistic.wdStatisticLines);
        }
    }

    Thursday, May 14, 2009 5:05 AM

All replies

  • Hi MuraliAsok!

    Have you tried using the paragraph count instead?



    Word._Document document;
    int numberOfParagraphs = document.Paragraphs.Count;

    Thursday, May 14, 2009 3:41 AM
  • HI
             Thanks for your sudden reply

    Actually i need the lines in each paragraphs also. With your suggestion i got the total paragraphs count in the document.

    Thanks 
    MuraliAsok

     

    Thursday, May 14, 2009 4:32 AM
  • Hi again!

    You can use the ComputeStatistics() method to count the lines for each paragraph in the document:


    int totalLineCount = 0;
    Word._Document document = CurrentDocument;

    foreach (Word.Paragraph paragraph in document.Paragraphs)
    {
        if (String.Empty != paragraph.Range.Text.Trim())
        {
            totalLineCount += paragraph.Range.ComputeStatistics(Word.WdStatistic.wdStatisticLines);
        }
    }

    Thursday, May 14, 2009 5:05 AM
  • Hi Jose Anton Bautista

    Its a great support from you and thanks alot. I am waiting for this type of a solution, thanks once again

    Friday, May 15, 2009 6:02 AM

  • Please note that I edited my previous code to include the IF statement inside the FOREACH loop.
    'hope that helps! : )

    Friday, May 15, 2009 7:13 AM