How to programatically (C#) determine the pages count of .docx files

后端 未结 4 1071
刺人心
刺人心 2020-12-11 17:22

I have about 400 files in .docx format, and I need to determine the length of each in #pages.

So, I want to write C# code for selecting the folder that contains the

4条回答
  •  渐次进展
    2020-12-11 18:00

    use DocumentFormat.OpenXml.dll you can find dll in C:\Program Files\Open XML SDK\V2.0\lib

    Sample code:

    DocumentFormat.OpenXml.Packaging.WordprocessingDocument doc = DocumentFormat.OpenXml.Packaging.WordprocessingDocument.Open(docxPath, false);
                MessageBox.Show(doc.ExtendedFilePropertiesPart.Properties.Pages.InnerText.ToString());
    

    to use DocumentFormat.OpenXml.Packaging.WordprocessingDocument class you need to add following references in your project

    DocumentFormat.OpenXml.dll & Windowsbase.dll

提交回复
热议问题