Select text by font in Word

Is there a way to extract all the lines that use a particular font (size, whether it is highlighted, font name, etc.) in a word through C #?

Also, is there a way to find out which font for any text is in the document?

My guess is that there are functions in the Microsoft.Office.Interop.Word namespace that can do this, but I cannot find them.

Edit: I am using word 2010.

+4
source share
1 answer

You can scroll through a document using the Find object from Word Interop. You can set the Find.Font.Name property to highlight or range from your document. Note that the Font interface has several Name* properties for different encodings.

EDIT

Here's the equivalent VBA code:

 Dim selectionRange As Range Set selectionRange = Application.ActiveDocument.Range With selectionRange.Find .ClearFormatting .Format = True .Font.NameBi = "Narkisim" //for doc without bidirectional script, use Name Do While .Execute MsgBox selectionRange.Text Loop End With 

The Word Interop object model is the same, see link above.

Do not ask me now C # code ... this is so, we do not make silver records. And if you ever work seriously with the Office Interop API, you will need to read the VBA code.

+2
source

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


All Articles