Reading the Statistics of a Word Document using

This code snippet helps you to read the Staticts Contents of Word Document Using

//Mark Reference to Microsoft Word 12.0 Object Library
//Project-RightClick-AddReference-ComTab-Microsoft Word 12.0 Object Library-Ok
//Create instance for the Word Object
Microsoft.Office.Interop.Word.Application ObjWord = new Microsoft.Office.Interop.Word.Application();
//Create default values
object falseValue = false;
object trueValue = true;
object missing = Type.Missing;
//set the options
object saveobjections = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
//Create instance for Word Document
Microsoft.Office.Interop.Word.Document wrdoc;
//Get the Filepath
//Your files should have in the Application path and insides files folder
object filepath = Server.MapPath(".") + @"\Files\" + @"MVP Nomination Form.doc";
//Open the File
wrdoc = ObjWord.Documents.Open(ref filepath, ref missing, ref trueValue, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
//Read the FileContents in A string Varriable
//Excluding the EndNotes and Annotions
Response.Write("Charcters No Spaces:" + wrdoc.ComputeStatistics(Microsoft.Office.Interop.Word.WdStatistic.wdStatisticCharacters, ref missing));
//With Spaces
Response.Write("Charcters With Spaces:" + wrdoc.ComputeStatistics(Microsoft.Office.Interop.Word.WdStatistic.wdStatisticCharactersWithSpaces, ref missing));

Response.Write("ParaGraphs:" + wrdoc.ComputeStatistics(Microsoft.Office.Interop.Word.WdStatistic.wdStatisticParagraphs, ref missing));
Response.Write("Pages:" + wrdoc.ComputeStatistics(Microsoft.Office.Interop.Word.WdStatistic.wdStatisticPages, ref missing));
//Lines Count
Response.Write("Lines:" + wrdoc.ComputeStatistics(Microsoft.Office.Interop.Word.WdStatistic.wdStatisticLines, ref missing));

//Close the Current document
ObjWord.Documents.Close(ref saveobjections, ref missing, ref missing);
//Quit word
ObjWord.Quit(ref saveobjections, ref missing, ref missing);



No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: