Search And Highlight text in aspose word

Hello,

I’ve run into some issues while trying to find and highlight text using aspose word it will working fine for string with out any special characters. if my string contain any special character the it will not working .

following link am using for find and highlight :https://docs.aspose.com/words/java/find-and-replace/

my string like below

getting an error that selected value/selected node is read-only. Does anyone know a workaround?I have a radtreeview nested within a deleted radcombobox. I need to be able to set the selected value or node but I keep getting an error that selected value/selected node is read-only. Does anyone know a workaround?I have a radtreeview nested within a radComboBox. I need to be able to set the selected value or node but I keep getting an error that selected value/selected node is read-only.

above link code not working for me if string is contain any white spaces or special characters please provide some solution

Hi Sreedhar,

Thanks for your inquiry. Please note that an exception is thrown if a captured or replacement string contains one or more special characters: paragraph break, cell break, section break, field start, field separator, field end, inline picture, drawing object, footnote.

It would be great if you please share following detail for investigation purposes.

  • Please attach your input Word document.

  • Please share the text (special characters) which you want to highlight.

  • Please attach the output Word file that shows the undesired behavior.

As soon as you get these pieces of information to us we’ll start our investigation into your issue.

Hi ,

Thanks for replay am attaching input document file and i want to highlight the following string in my word document getting an error that selected value/selected node is read-only. Does anyone know a workaround?I have a radtreeview nested within a deleted radcombobox. if string is "getting an error that selected value/selected node is read-only." then highlight working fine but i want to highlight total phrase and is there any option to highlight the string with line breaks…

Hi Sreedhar,

Thanks for sharing the document. You document contains Non-breaking spaces. In this case, I suggest you please use following code example. I have attached the output document with this post for your kind reference.

Document doc = new Document(MyDir + "input.docx");
doc.getRange().replace(ControlChar.NON_BREAKING_SPACE_CHAR + "", " ", false, false);
String strName = "getting an error that selected value/selected node is read-only. Does anyone know a workaround\\?I have a radtreeview nested within a deleted radcombobox.";
Pattern regex = Pattern.compile(strName, Pattern.CASE_INSENSITIVE);
doc.getRange().replace(regex, new ReplaceEvaluatorFindAndHighlight(), false);
// Save the output document.
doc.save(MyDir + "Out.docx");

Hi Tahir Manzoor,

Thanks for Your solution . may i know why your putting “” in Does anyone know a workaround? and your solution not working if document contain 2 paras and replace text contain half text in first para and remaining text in second para in this scenario how can we replace the text and how can we replace with line breaks and sentence breaks please provide perfect solution to replace any string with any format

my document contain paragraphs, images ,links, tables… and replace text will come dynamically then how can i maintain all these things

Thanks

Hi Sreedhar,

Thanks for your inquiry.

*sreedhar.dharanikota:

may i know why your putting “” in Does anyone know a workaround?*

The first parameter of Range.Replace method is Regex. In your case, you want to find the question mark (?) text using Regex. So you need to escape question mark (?) with two backslashes ‘?’.

*sreedhar.dharanikota:

and your solution not working if document contain 2 paras and replace text contain half text in first para and remaining text in second para in this scenario how can we replace the text and how can we replace with line breaks and sentence breaks please provide perfect solution to replace any string with any format*

You need to create the regular expression which matches the complete text (both paragraphs) . If text is not according to document, the text will not be highlighted.

In this case, I offer you following solution.

  1. Please find the start of text (e.g first 10 characters of your first paragraph) using the same approach and insert a bookmark e.g bookmark1
  2. Please find the end of text (e.g last 10
    characters of your last or second paragraph) using the same approach and insert a
    bookmark e.g bookmark2
  3. After inserting bookmarks, you can highlight the text between these two bookmarks. For this, you need to get the Run nodes between these two bookmarks and highlight the color of Run node using Run.setHighlightColor method.

Hope this helps you. Please let us know if you have any more queries.

Hi ,

Thanks for your replay by your solution am not getting perfect output as per my requirement am facing following problems while highlighting

  1. if my text contain same phrase of content multiple time then it’s highlighting on first occurrence

Output Text:
getting an error that selected value/selected node is read-only. Does anyone know a workaround?I have a radtreeviewnested within a radComboBox. mrityunjay new code I need to be able to set the selected value or node but I keepgetting an error that selected value/selected node is read-only. Does anyone know a workaround?I have a radtreeviewnested within a radComboBox. I need to be able to set the selected value or node but I keep getting an error that selected value/selected node is read-only. Does anyone know a workaround?I have a radtreeviewnested within a radComboBox. version 5 1 version 6

  1. some times its highlights total paragraph irrespective bookmarks

Output Text:

getting an error that selected value/selected node is read-only. Does anyone know a workaround?I have a radtreeview nested within a radComboBox. mrityunjay new code I need to be able to set the selected value or node but I keep getting an error that selected value/selected node is read-only. Does anyone know a workaround?I have a radtreeview nested within a radComboBox. I need to be able to set the selected value or node but I keep getting an error that selected value/selected node is read-only. Does anyone know a workaround?I have a radtreeview nested version 5 1 version 6

in above text my highlight text only "selected value or node but I keep getting an error that selected value/selected node is read-only. Does anyone know a workaround?I have a radtreeview nested within a radComboBox. " but my book marks approach total text get highlighted.

3.if my content having any headings then text not get highlighted

4.if any table contain between 2 bookmarks then text not get highlighted

please provide a generic solution to work in all approaches.

Thanks

Hi ,

am Attaching my documents input document and what i want to highlighting in other document section wise

in

section 1 Highlight simple text

section 3 Highlight text and its appearing 2 times in section content if am using book marks approach only first time it’s get highlighted

section 4 i have 2 highlight contents

first one simple text and other contain table then that text not get highlighted

section 4.2
i want only text highlight but book marks approach to paragraph get highlighted as mentioned in above thread

and

if highlight text contain any heading then my text not get highlighted

please provide solution in above scenarios not specific please provide solution for generic that can work in any text …

please provide solution ASAP

Thanks

Hi Sreedhar,

Thanks for your inquiry. Could you please share the input documents for which you are facing the issues? Please also share the text which you want to highlight for each input document. I will investigate the issue on my side and provide you more information.