Udit Sharma

Udit Sharma

  • NA
  • 149
  • 3.1k

How to get exact no of page , word and character counts

Jul 3 2019 12:02 AM
I just want to get page characteristics. I have tried many scripts but not getting the exact output. My code giving me the following output :
 
 
But the exact output in the document is as follows :
 
Here is my code:
  1. static void CountwithInterOp(object path)   
  2. {     
  3.    Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();  
  4.     object miss = System.Reflection.Missing.Value;  
  5.     object readOnly = true;  
  6.     Microsoft.Office.Interop.Word.Document docs = word.Documents.Open(ref path, ref miss, ref readOnly, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);  
  7.     Microsoft.Office.Interop.Word.WdStatistic stat = Microsoft.Office.Interop.Word.WdStatistic.wdStatisticPages;   
  8.   docs.Activate();   
  9.   int numout = docs.ComputeStatistics(stat, ref miss);   
  10.   int wordcountout = docs.ComputeStatistics(WdStatistic.wdStatisticWords, ref miss);   
  11.   int CharactersWithSpaces=  docs.ComputeStatistics(WdStatistic.wdStatisticCharactersWithSpaces, ref miss);   
  12.   Console.WriteLine("Pages: " + numout);  
  13.    Console.WriteLine("CharactersWithSpaces: " + CharactersWithSpaces);   
  14.   Console.WriteLine("Words: " + wordcountout);   
  15.   Console.ReadLine();   
  16.   docs.Close(false);  
  17.  }  
I have tried with different code with many different dlls but getting the same output. 

Answers (2)