![search word files for text string search word files for text string](https://cdn.crunchify.com/wp-content/uploads/2015/10/Count-total-number-of-Characters-Words-and-Lines.png)
If (docPackageRelationship IsNot Nothing) Thenĭim documentUri As Uri = PackUriHelper.ResolvePartUri(New Uri("/", UriKind.Relative), docPackageRelationship.TargetUri)ĭim documentPart As PackagePart = wdPackage.GetPart(documentUri) Using wdPackage As Package = Package.Open(fileName, FileMode.Open, FileAccess.Read)ĭim docPackageRelationship As PackageRelationship = wdPackage.GetRelationshipsByType(documentRelationshipType).FirstOrDefault() Private Function GetStyleOfParagraph(ByVal styleNode As XElement, ByVal defaultStyle As String) As String ' Following function is required because Visual Basic doesn't support short circuit evaluation Return (e.).StringConcatenate(Function(element) CStr(element)) Public Function ParagraphText(ByVal e As XElement) As String
![search word files for text string search word files for text string](https://i.stack.imgur.com/fVBh0.png)
Public Function StringConcatenate(Of T)(ByVal source As IEnumerable(Of T), _īyVal func As Func(Of T, String)) As StringīyVal func As Func(Of T, String), ByVal separator As String) As String Public Function StringConcatenate(ByVal source As IEnumerable(Of String)) As Stringĭim sb As StringBuilder = New StringBuilder() Following is the new query that retrieves all paragraphs (string)style.Attribute(w + "default") = "1" Where (string)style.Attribute(w + "type") = "paragraph" & StyleDoc = XDocument.Load(XmlReader.Create(stylePart.GetStream())) įrom style in (w + "style") Load the style XML in the part into an XDocument instance. PackagePart stylePart = wdPackage.GetPart(styleUri) PackUriHelper.ResolvePartUri(documentUri, styleRelation.TargetUri) There will only be one.ĭocumentPart.GetRelationshipsByType(stylesRelationshipType).FirstOrDefault() XDoc = XDocument.Load(XmlReader.Create(documentPart.GetStream())) Load the document XML in the part into an XDocument instance. PackagePart documentPart = wdPackage.GetPart(documentUri) Uri documentUri = PackUriHelper.ResolvePartUri(new Uri("/", UriKind.Relative), WdPackage.GetRelationshipsByType(documentRelationshipType).FirstOrDefault() PackageRelationship docPackageRelationship = Using (Package wdPackage = Package.Open(fileName, FileMode.Open, FileAccess.Read)) StringConcatenate(element => (string)element) Ĭonst string fileName = "SampleDoc.docx" Public static string ParagraphText(XElement e) Public static string StringConcatenate(this IEnumerable source, string separator) Public static string StringConcatenate(this IEnumerable source, Public static string StringConcatenate(this IEnumerable source) It uses types in the System.IO.Packaging namespace. This example uses classes found in the WindowsBase assembly. The instructions for creating the source document for this example are in Create the source Office Open XML document. The added query is pointed out by comments in the code. The example builds on the previous examples in this tutorial. This example finds all occurrences in a WordprocessingML document of a specific piece of text (the string "Hello"). Example: Find all occurrences of a string in a WordProcessingML document This article extends the previous queries to find all occurrences of a string in a WordProcessingML document.