使用VB.NET检查Word文档中的字体样式 [英] Checking Font Styles In Word Document Using VB.NET
问题描述
我想使用vb.net检查一个Word文件,并检查文档中的样式是否正确.
i want to check a word file using vb.net and check that the styles in the document are proper or not.
我必须检查Word文档中的这些表达式
I have to check for these expressions in word document
a.Verdana + 16 pt + Bold + Red
b.Verdana + 12 pt + Bold + Italic + Blue
c.Verdana + 11 pt + Bold + Italic + Brown
d.Arial + 10 pt + Black
我已经尝试过了
If objDoc.Range.Font.Name = "Arial" And objDoc.Range.Font.Size = 10 Then
If objDoc.Range.Font.Color = WdColor.wdColorBlack Then
End If
MsgBox("ok")
Else
MsgBox("not ok")
End If
但是使用此代码,仅当整个单词文档由Arial,10,Black
组成时,它才显示msgbox确定",而当由上述表达式组成时,除了Arial,10,Black
But with this code it shows msgbox "OK" only when the whole word document consist of Arial,10,Black
and shows msgbox "Not Ok" when it consist the above expressions except for the Arial,10,Black
因此,基本上,我需要帮助才能找到由上述所有表达式/样式组成的同一个word文档中的所有表达式.
So basically i need help to find out all the expressions in the same word document which consist of all the above expressions/Styles.
任何帮助都是非常可观的. 请帮我解决这个问题,仍然找不到解决方法.
Any Help will be really really appreciable.. Plz help me with this still not able to find a solution..
推荐答案
使用下面的代码,您可以找到字体样式不同的句子.
With the foolowing code you can find sentences where font style is different.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim oDoc As New Word.Document()
Dim wapp As New Word.Application()
Try
oDoc = wapp.Documents.Open(TextBox1.Text & "\" & "TEST.doc")
For Each Senetence As Word.Range In oDoc.Sentences
For Each Character As Word.Range In Senetence.Characters
If Character.Font.Name <> "Verdana" AndAlso Character.Font.Name <> "Arial" Then
MsgBox(" Font Name not matching Error Line number " & Senetence.Text)
Exit For
End If
Next
Next
oDoc.Close()
Catch ex As Exception
oDoc.Close()
End Try
End Sub
这篇关于使用VB.NET检查Word文档中的字体样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!