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

OpenXML extract Highlighted text from word document with c#

我用了下面的,但是不行

Dim htext= wordDocument.MainDocumentPart
                       .Document
                       .Descendants(Of Highlight)()
                       .Where(Function(h) h.Val = "yellow")
                       .ToList()

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

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