Dim doc As JavaObject = OpenDocx(Dir, FileName)
Dim paragraphs As List = doc.RunMethod("getParagraphs", Null)
For Each p As JavaObject In paragraphs
Dim runs As List = p.RunMethod("getRuns", Null)
If runs.IsInitialized Then
For Each r As JavaObject In runs
Dim text As String = r.RunMethod("getText", Array(0))
If text <> Null Then
Log(text)
For Each key As String In m1.Keys
'If text.Contains("$" & key & "$") Then <<- this was from original code whcih made use of Excel as first step
If text.Contains(key) Then
Log(key)
r.RunMethod("setText", Array(m1.Get(key), 0))
End If
Next
End If
Next
End If
Next
Sub SaveDocument(doc As JavaObject, Dir As String, FileName As String)
Dim out As OutputStream = File.OpenOutput(Dir, FileName, False)
doc.RunMethod("write", Array(out))
out.Close
End Sub
Sub OpenDocx(Dir As String, FileName As String) As JavaObject
Dim in As InputStream = File.OpenInput(Dir, FileName)
Dim document As JavaObject
document.InitializeNewInstance("org.apache.poi.xwpf.usermodel.XWPFDocument", Array(in))
Return document
End Su