![]() ![]() Whilst it would seem that you should be able to work the other way around (count everything, delete everything that is bold, italic and/or underline in one go, subtract what's left, then undo the deletion), Word has no generic 'underlined' property that Very fast, even on a long document (takes a few seconds on a 75-page document). You could count everything, delete everything that is not bold, italic and/or underline in one go, subtract what's left, then undo the deletion. Besides, I'm not sure how much detail you want. I could have implemented a three-level loop to toggle the various font attibutes, but I thought I'd take a linear approach for clarity. M - p & " bold italic underline characters found." & vbCr L - o & " italic underline characters found." & vbCr & _ ![]() K - n & " bold underline characters found." & vbCr & _ J - m & " bold italic characters found." & vbCr & _ J - l & " italic (only) characters found." & vbCr & _ J - k & " bold (only) characters found." & vbCr & _ I - j & " plain characters found." & vbCr & _ StrMsg = i & " characters in the document." & vbCr & _ ReleaseComObject(wordApplication) ĭim i As Long, j As Long, k As Long, l As Longĭim m As Long, n As Long, o As Long, p As Long WordDocument.Close(SaveChanges: WdSaveOptions.wdDoNotSaveChanges) Int newItalic = totalChar - Ĭ = WdUnderline.wdUnderlineNone Ref missing, ref missing, ref missing, ref missing) Ref missing, ref missing, ref missing, ref replaceAll, Ref missing, ref missing, ref missing, ref missing, Object replaceAll = WdReplace.wdReplaceAll Ĭ( ref missing, ref missing, ref missing, WordApplication.DisplayAlerts = WdAlertLevel.wdAlertsNone ĭocument wordDocument = (wordFileName, ReadOnly: true, AddToRecentFiles: false, Visible: false) Public void ProcessWordDocument( string wordFileName)Īpplication wordApplication = new ApplicationClass() If someone known a better way, please let me know. i have also see the following link that uses Range.Find, still its slow. I looked up a lot of forum and msdn but i haven't found a reasonably fast solution. List wordRange = (from f in ()īut here again it takes 1.5 minutes which again is a lot of time to process a document. I tweaked this code a bit by first getting a collection of Word (words that have Bold, Italic or Underline) and then loop through the individual characters in the short listed word to find Bold, Underline and Italic. The problem with this code is that the Linq takes a lot of time to get list of Character (Range), approx 10.5 minutes per document. Then looping through the collection get the number of Bold, Italic and Underline characters that are either Bold, Underline or Italic for a given Range (which is generally my document content). In the above code i am first getting a collection of Range i.e. Where f.Font.Bold = -1 || f.Font.Italic = -1 || f.Font.Underline != WdUnderline.wdUnderlineNone Although i have a working code, it is very slow and take lot of time when parsing a Word Document that has say 10-15 pages. Hi i am looking for some help in counting number of Bold, Underline and Italic characters in a Word Document. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |