Class ReplaceAction

  • java.lang.Object
    • com.aspose.words.ReplaceAction
public class ReplaceAction 
extends java.lang.Object

Utility class containing constants. Allows the user to specify what happens to the current match during a replace operation.


Shows how to insert content of one document into another during a customized find and replace operation.
public void insertDocumentAtReplace() throws Exception {
    Document mainDoc = new Document(getMyDir() + "Document insertion destination.docx");

    FindReplaceOptions options = new FindReplaceOptions();
    options.setReplacingCallback(new InsertDocumentAtReplaceHandler());

    mainDoc.getRange().replace(Pattern.compile("\\[MY_DOCUMENT\\]"), "", options); + "InsertDocument.InsertDocumentAtReplace.doc");

private class InsertDocumentAtReplaceHandler implements IReplacingCallback {
    public int replacing(final ReplacingArgs args) throws Exception {
        Document subDoc = new Document(getMyDir() + "Document.docx");

        // Insert a document after the paragraph, containing the match text
        Paragraph para = (Paragraph) args.getMatchNode().getParentNode();
        insertDocument(para, subDoc);

        // Remove the paragraph with the match text

        return ReplaceAction.SKIP;
See Also:
IReplacingCallback, Range, Range.replace(java.lang.String,java.lang.String,com.aspose.words.FindReplaceOptions)

Field Summary
static final intREPLACE = 0
Replace the current match.
static final intSKIP = 1
Skip the current match.
static final intSTOP = 2
Terminate the replace operation.

    • Field Detail

      • REPLACE = 0

        public static final int REPLACE
        Replace the current match.
      • SKIP = 1

        public static final int SKIP
        Skip the current match.
      • STOP = 2

        public static final int STOP
        Terminate the replace operation.