FindAll.vb
  1. ''
  2. '' This code is part of Document Solutions for Word demos.
  3. '' Copyright (c) MESCIUS inc. All rights reserved.
  4. ''
  5. Imports System.IO
  6. Imports System.Drawing
  7. Imports System.Linq
  8. Imports GrapeCity.Documents.Word
  9.  
  10. '' This sample shows how to find all occurrences of a string
  11. '' in a DOCX document (see JsFrameworkExcerpt) using the
  12. '' RangeBase.Find extension method provided by the
  13. '' RangeBaseFindReplaceExtensions class.
  14. Public Class FindAll
  15. Public Function CreateDocx() As GcWordDocument
  16. '' The string to find. Note that we use all lowercase,
  17. '' as we specify the ignore case option in the find call
  18. Const findPattern = "javascript framework"
  19.  
  20. '' Load the document:
  21. Dim doc = New GcWordDocument()
  22. doc.Load(Path.Combine("Resources", "WordDocs", "JsFrameworkExcerpt.docx"))
  23.  
  24. '' Find all occurrences of the search string, ignoring the case:
  25. Dim finds = doc.Body.Find(findPattern, New FindOptions(doc) With {.IgnoreCase = True})
  26.  
  27. '' Print the number of found occurrences at the top of the document
  28. doc.Body.Paragraphs.Insert($"Found {finds.Count()} occurrences of '{findPattern}' in the document." + vbCrLf + vbCrLf, InsertLocation.Start)
  29.  
  30. '' Done
  31. Return doc
  32. End Function
  33. End Class
  34.