【C# Office】Get PageCount of Word

object file = fileFullName; object Nothing; Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.ApplicationClass(); Nothing = System.Reflection.Missing.Value; Document doc = wordApp.Documents.Open(ref file, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing); //int pageCount = (int)(doc.Content.get_Information(WdInformation.wdActiveEndAdjustedPageNumber)); int pageCount=doc.ComputeStatistics( Microsoft.Office.Interop.Word.WdStatistic.wdStatisticPages,ref Nothing); doc.Close(ref Nothing, ref Nothing, ref Nothing); wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);

 

 

 

Rem:

To count the pages in MSWord document, we need to follow following steps: 

1 Create an object of Word Application. 
2 Open the required Word document using the open() function of Documents collection of Word document. This function returns the Word.Document object. 
3 Cal the ComputeStatistics fumction on Word.Document object passing it an enum WdStatistic with value equal to wdStatisticPages. This function will return the number of pages in the opened word document.

你可能感兴趣的:(function,object,C#,File,Office)