Programmatically count the number of characters / words / paragraphs with a specific style in a DOCX document

I need to programmatically count the characters and / or words and / or paragraphs that have been applied to a specific known style in a DOCX document.

I need to know 1) if possible, and 2) any clues as to where I can start solving this problem.

I am familiar with DOM navigation, XPath / XQuery and can use .NET, PHP or Java or any other tool while I can solve this problem.

+6
source share
1 answer
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application(); Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document(); try { object fileName = @"C:\TT\change.docx"; doc = word.Documents.Open(ref fileName, 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, ref missing, ref missing); doc.Activate(); int count = doc.Characters.Count ; int words = doc.Words.Count; ; int paragraphs = doc.Paragraphs.Count; doc.Save(); doc.Close(ref missing, ref missing, ref missing); word.Application.Quit(ref missing, ref missing, ref missing); } catch (Exception ex) { doc.Close(ref missing, ref missing, ref missing); word.Application.Quit(ref missing, ref missing, ref missing); } 
+2
source

Source: https://habr.com/ru/post/886915/


All Articles