Vb.net OpenXML使用c从word文档中提取突出显示的文本#
我使用了下面的方法,但它不起作用Vb.net OpenXML使用c从word文档中提取突出显示的文本#,vb.net,openxml,Vb.net,Openxml,我使用了下面的方法,但它不起作用 Dim htext= wordDocument.MainDocumentPart .Document .Descendants(Of Highlight)() .Where(Function(h) h.Val = "yellow") .ToList() 使用此方法获取高亮显示文本
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
使用此方法获取高亮显示文本的列表
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
必须重建我的解决方案。我把我的包裹弄坏了。我最迟在星期一之前答复。谢谢你的帮助。似乎没有注意到突出显示的项目。每次运行的检查都不是空的,因为“无”总是空的。我传递了一个WordProcessingdocument,这不正确吗?RunProperties不正确,至少得到了突出显示的文本。我修复了文档中的突出显示。一旦解决了这个问题,我将If条件更改为highlightVal.Val.Value.Equals(HighlightColorvalues.Yellow),现在我得到了所有突出显示的值。只是想知道如何根据每一段来完成它?不能添加我的代码示例,我用它来完成我需要的工作。必须重新构建我的解决方案。我把我的包裹弄坏了。我最迟在星期一之前答复。谢谢你的帮助。似乎没有注意到突出显示的项目。每次运行的检查都不是空的,因为“无”总是空的。我传递了一个WordProcessingdocument,这不正确吗?RunProperties不正确,至少得到了突出显示的文本。我修复了文档中的突出显示。一旦解决了这个问题,我将If条件更改为highlightVal.Val.Value.Equals(HighlightColorvalues.Yellow),现在我得到了所有突出显示的值。只是想弄清楚如何让每一段都有效果?不能添加我的代码示例,我用它来实现我所需要的效果。