Some Words not get Replaced Properly Please help me to replace this content. I have highlighted not replaced content. Also please provide the solution to remove the replaced content highlight color. i have attached document and issue screenshot here.PFA.
I have used below code:
doc.Document doc4 = new doc.Document(MyDir + "TableProcess.docx");
doc.Tables.Table table2 = (doc.Tables.Table)doc4.GetChild(doc.NodeType.Table, 0, true);
FindReplaceOptions opts1 = new FindReplaceOptions();
table2.Range.Replace("&lowst0", "0", opts1);
table2.Range.Replace("&lowet20", "20", opts1);
table2.Range.Replace("&midst40", "40", opts1);
table2.Range.Replace("&midet60", "60", opts1);
table2.Range.Replace("&d1", "1", opts1);
table2.Range.Replace("&highst80", "800", opts1);
table2.Range.Replace("&ac", "123", opts1);
doc4.Save(MyDir + "TableReplaceCellTextOut.docx");
AsposeTicket.zip (75.6 KB)
@thiru1711 This is not a bug and replacement works properly. The issue occurs because &
character is used by Aspose.Words for escaping metacharacters, like line break or page break. Please see our documentation for more information:
https://reference.aspose.com/words/net/aspose.words/range/replace/
So to get the desired result you should escape &
character with another &
character:
table2.Range.Replace("&&lowst0", "0", opts1);
To remove highlight color you can use FindReplaceOptions.ApplyFont. For example see the following code:
FindReplaceOptions opts1 = new FindReplaceOptions();
opts1.ApplyFont.HighlightColor = Color.Empty;
table2.Range.Replace("&&lowst0", "0", opts1);
table2.Range.Replace("&&lowet20", "20", opts1);
table2.Range.Replace("&&midst40", "40", opts1);
table2.Range.Replace("&&midet60", "60", opts1);
table2.Range.Replace("&&d1", "1", opts1);
table2.Range.Replace("&&highst80", "800", opts1);
table2.Range.Replace("&&ac", "123", opts1);