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.
WHAT IS THE PURPOSE OF USING ITALICS IN MICROSOFT WORD CODE
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. If, however, the whole paragraph had been formatted green over the top of Heading 1, and I applied Heading 2, then I'd expect Heading 2 to be applied and the green to disappear.Hi i am looking for some help in counting number of Bold, Underline and Italic characters in a Word Document. If, for example, I had a paragraph in style Heading 1 and the text was "The sinking of the Titanic" and I applied Heading 2 to that paragraph, then you'd expect the Titanic to retain its italics. The general rule is that if you apply a paragraph style to a paragraph then direct formatting (like italic) will be retained where it covers less than half the text in the paragraph, and rejected when it covers more than half (Figures 2 and 3). What happens when you apply a paragraph style to a paragraph that already has direct formatting? On top of the paragraph style, you can apply additional formatting, like bold or italics or pink or small caps to the words that need them (Figure 1). It also stores instructions about font formatting (bold, italics, colour, superscript etc). The words "King Lear" have direct italic formatting applied.Įvery paragraph has a paragraph style attached to it, whether you like it or not.Ī paragraph style not only stores instructions about paragraphs (indents, line spacing etc). Figure 1: The paragraph style applied to this text has the font defined as Times New Roman, 11pt, not bold and not italics.