Example usage for org.apache.poi.hwpf.usermodel Range insertAfter

List of usage examples for org.apache.poi.hwpf.usermodel Range insertAfter

Introduction

In this page you can find the example usage for org.apache.poi.hwpf.usermodel Range insertAfter.

Prototype

public CharacterRun insertAfter(String text) 

Source Link

Document

Inserts text onto the end of this range

Usage

From source file:b01.officeLink.ExtendedWordDocument.java

License:Apache License

public void replace(TextPiece textPiece, int start, int end, String newText) {
    int lengthToReplace = end - start;
    if (newText.length() < lengthToReplace) {
        int gap = lengthToReplace - newText.length();
        for (int i = 0; i < gap; i++) {
            if (i < gap / 2) {
                newText = " " + newText;
            } else {
                newText = newText + " ";
            }//w  ww .  j  av  a  2  s  .c  o  m
        }
    }

    StringBuffer buffer = textPiece.getStringBuffer();

    buffer.replace(start, end, newText.substring(0, lengthToReplace));
    Range range = new Range(start, end, getHwpfDocument());
    range.insertAfter(newText.substring(lengthToReplace));
}