OpenXML使用c#从word文档中提取突出显示的文本

时间:2016-06-08 15:40:07

标签: vb.net openxml

我使用了以下内容,但它不起作用

compile 'com.android.support:design:23.4.0'
compile 'com.android.support:appcompat-v7:23.4.0'

1 个答案:

答案 0 :(得分:4)

使用此方法获取突出显示的文本列表。

Private Function GetListOfHighlightedString(ByVal Docx As WordprocessingDocument) As List(Of String)
                Dim lstOfHighlightedString As List(Of String) = New List(Of String)()
                Try
                    For Each EachRun In Docx.MainDocumentPart.Document.Body.Descendants(Of Run)()
                        If EachRun.RunProperties IsNot Nothing Then
                            For Each EachPrpChild In EachRun.RunProperties.ChildElements
                                If TypeOf EachPrpChild Is Highlight Then
                                    Dim highlightVal As Highlight = TryCast(EachPrpChild, Highlight)
                                    If highlightVal.Val.Equals(HighlightColorValues.Yellow) Then
                                        lstOfHighlightedString.Add(EachRun.InnerText)
                                    End If
                                End If
                            Next EachPrpChild
                        End If
                    Next EachRun
                Catch e1 As Exception

                    Throw
                End Try
                Return lstOfHighlightedString