com.aspose.words

Class FindReplaceDirection

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

Utility class containing constants. Specifies direction for replace operations.

Example:

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() + "InsertDocument1.doc");

    FindReplaceOptions options = new FindReplaceOptions();
    options.setDirection(FindReplaceDirection.BACKWARD);
    options.setReplacingCallback(new InsertDocumentAtReplaceHandler());

    mainDoc.getRange().replace(Pattern.compile("\\[MY_DOCUMENT\\]"), "", options);
    mainDoc.save(getMyDir() + "\\Artifacts\\InsertDocumentAtReplace.doc");
}

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

        // 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.
        para.remove();

        return ReplaceAction.SKIP;
    }
}

Field Summary
static final intFORWARD = 0
Matched items are replaced from first to last.
static final intBACKWARD = 1
Matched items are replaced from last back to first.
 

    • Field Detail

      • FORWARD = 0

        public static final int FORWARD
        Matched items are replaced from first to last.
      • BACKWARD = 1

        public static final int BACKWARD
        Matched items are replaced from last back to first.