B4J Question [SOLVED] Replace Text in a Word-Document-HEADER

Updated code that replaces text in the headers and document body:
Code:
Dim m As Map = CreateMap("HEADER": "asdasd")

Dim doc As JavaObject = OpenDocx("C:\Users\H\Downloads\TEST1.docx", "")
Dim AllParagrpahs As List
AllParagrpahs.Initialize
Dim headers As List = doc.RunMethod("getHeaderList", Null)
For Each header As JavaObject In headers
   AllParagrpahs.AddAll(header.RunMethod("getParagraphs", Null))
Next
AllParagrpahs.AddAll(doc.RunMethod("getParagraphs", Null))
For Each p As JavaObject In AllParagrpahs
   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
               For Each key As String In m.Keys
                   If text.Contains("$"&key&"$") Then
                       r.RunMethod("setText", Array(""&m.Get(key)&"", 0))
                   End If
               
               Next
               End If
       Next
   End If
Next
SaveDocument(doc, "C:\Users\H\Downloads\TEST2.docx", "")
 
Upvote 0
... there is a new problem:
When i want to print out this WORD-document, there is the message:
Error! Reference source not found! :confused:
 
Upvote 0
It has nothing to do with the header text, it is always the same to all text.
Just open the attached file "output.docx".

The first time everything looks good, but ...
I am not able to print it
 

Attachments

Upvote 0
Back
Top