Hi I have a code which i used to run on word platform. I swiched to aspose a while ago.
I am not able to find any reference where i can replace the text at certain position in a range with the text entered. I mean i see delete range option but no insert and remove text from position 1 to position 2.
Please refer me to something if it is previously posted.
Should be easy but i have spent enormous time searching for it in aspose platform.
Thanks,
Chirag
Hi Chirag,
Thanks for your inquiry. I suggest you please read following article about find and replace text.
https://docs.aspose.com/words/java/find-and-replace/
Please check the code example shared in following documentation link for your kind reference.
https://docs.aspose.com/words/java/find-and-replace/
Hope this helps you. Please let us know if you have any more queries.
Hi Tahir,
Here is the document which i wanted to update the content.
We have a bookmark called content. from where we take the starting postion from which we need to update the document. We give the user the content of the document between the bookmark and the end of the document. User edits the content and we write back the contents in plain text.
This is the scenario we want to replicate in aspose. I havent been able to understand how find and replace or how to find and highlight text will serve this purpose.
Find and replace wont work as aspose does not look for such a long set of string. Even if it does it then too it will require to have all the punctuation and other hidden characters. The same thing with Find and Highlight has.
We need to take the position and replace the text till the end.
Here is how we do this with word objects.
***** To fetch the text ****
For Each bm In doc.Range.Bookmarks
If (bm.Name = "CONTENT") Then
txtArea.Text = doc.Range(bm.Start, doc.Range.End).Text
Exit For
End If
Next
to Update the Text. ******
For Each bm In doc.Range.Bookmarks
If (bm.Name = "CONTENT") Then
doc.Range(bm.Start + 1, doc.Range.End).Text = txtArea.Text
bm.Select()
Exit For
End If
Next
Hi Chirag,
Thanks for sharing the detail. Following code example remove the contents from bookmark to the end of document. After deleting the contents you can insert the new content. Hope this helps you. Please let us know if you have any more queries.
Dim doc = New Document(MyDir + "100_9129908_TEST_1_A.docx")
Dim builder = New DocumentBuilder(doc)
builder.MoveToBookmark("Content")
builder.InsertBreak(BreakType.SectionBreakContinuous)
Dim section = DirectCast(builder.CurrentSection.PreviousSibling, Section)
'remvoe contents from bookmark to the end of document.
While Not section.Equals(doc.LastSection)
doc.LastSection.Remove()
End While
builder.MoveToDocumentEnd()
''Insert new contents
''Your code...