I have a whole lot of documents where the are a kind of formfields.
These fields all start and end with @ and everything (including @) is double underlined.
I implemented a search and replace routine but Aspose doesn’t find the text properly.
Attached is a test document that I use for searching. When you start the app the first text that is found is ‘@Kund’, the second one is ‘_Briefkopf!@’ where all this is a single text in the input document.
Am I doing something wrong or is this a bug?
Thomas
Hi Thomas,
Sub Main()<o:p></o:p>
Dim filename As String = ".\anfangstext.doc"
Dim doc As New Aspose.Words.Document(filename)
doc.JoinRunsWithSameFormatting()
FillWordFields(doc)
doc.Save(".\AfterSearch.doc")
Console.WriteLine("Search/Replace finished")
Console.WriteLine("Output saved in .\AfterSearch.doc")
Console.ReadKey()
End Sub
Private Sub FillWordFields(doc As Aspose.Words.Document)
Dim options As New Replacing.FindReplaceOptions
options.ReplacingCallback = New MyReplaceEvaluator
AddHandler CType(options.ReplacingCallback, MyReplaceEvaluator).FillReplace, AddressOf DoFillReplace
doc.Range.Replace(New Text.RegularExpressions.Regex("(?<=@)(.*?)(?=@)"), "", options)
End Sub
Private Sub DoFillReplace(Textrun As Run, Formfield As String)
Dim newvalue As String = "Newvalue:" + Textrun.Text.Replace("@", "")
Textrun.Font.Underline = Underline.None
Textrun.Text = newvalue
End Sub
Works like a charm. Thanks
Thomas
Hi Thomas,