Hello Aspose team,
I want to find the text and delete the line.
I have found the following code from https://forum.aspose.com/t/remove-the-line-in-word-file-when-certain-text-match/59964/2
public class DeleteLine {
public static void main(String[] args) throws Exception {
Document doc = new Document("E:\\Project\\Sprint 19\\Test_Aspose_Doc\\Test.docx");
Pattern regex = Pattern.compile("SOWPH_Test", Pattern.CASE_INSENSITIVE);
doc.getRange().replace(regex, new ReplaceEvaluatorFindAndremoveParagraph(), false);
doc.save("E:\\Project\\Sprint 19\\Test_Aspose_Doc\\PageNumbering\\Test111out.docx");
System.out.println("Done............");
}
}
class ReplaceEvaluatorFindAndremoveParagraph implements IReplacingCallback
{
public int replacing(ReplacingArgs e) throws Exception
{
Node currentNode = e.getMatchNode();
if (currentNode.getNodeType() == NodeType.RUN)
{
((Run) currentNode).getParentParagraph().remove();
}
return ReplaceAction.SKIP;
}
}
I facing compilation issue for the above code
Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method replace(Pattern, String, FindReplaceOptions) in the type Range is not applicable for the arguments (Pattern, ReplaceEvaluatorFindAndremoveParagraph, boolean)
Please let me know If I am doing anything wrong.