use of org.apache.poi.hwpf.usermodel.Range in project poi by apache.
the class HWPFDocument method delete.
public void delete(int start, int length) {
Range r = new Range(start, start + length, this);
r.delete();
}
use of org.apache.poi.hwpf.usermodel.Range in project poi by apache.
the class QuickTest method main.
public static void main(String[] args) throws IOException {
HWPFDocument doc = new HWPFDocument(new FileInputStream(args[0]));
Range r = doc.getRange();
System.out.println("Example you supplied:");
System.out.println("---------------------");
for (int x = 0; x < r.numSections(); x++) {
Section s = r.getSection(x);
for (int y = 0; y < s.numParagraphs(); y++) {
Paragraph p = s.getParagraph(y);
for (int z = 0; z < p.numCharacterRuns(); z++) {
// character run
CharacterRun run = p.getCharacterRun(z);
// character run text
String text = run.text();
// show us the text
System.out.print(text);
}
// use a new line at the paragraph break
System.out.println();
}
}
doc.close();
}
use of org.apache.poi.hwpf.usermodel.Range in project poi by apache.
the class TestBookmarksTables method testDeleteRange.
public void testDeleteRange() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("pageref.doc");
Range range = new Range(27, 41, doc);
range.delete();
assertEquals(0, doc.getBookmarks().getBookmarksCount());
}
use of org.apache.poi.hwpf.usermodel.Range in project poi by apache.
the class TestBookmarksTables method testReplaceTextAfter.
public void testReplaceTextAfter() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("pageref.doc");
Bookmark bookmark = doc.getBookmarks().getBookmark(0);
Range range = new Range(bookmark.getStart(), bookmark.getEnd(), doc);
range.replaceText("1destin2ation3", true);
bookmark = doc.getBookmarks().getBookmark(0);
assertEquals("userref", bookmark.getName());
assertEquals(27, bookmark.getStart());
assertEquals(41, bookmark.getEnd());
}
use of org.apache.poi.hwpf.usermodel.Range in project poi by apache.
the class TestBookmarksTables method testUpdateText.
public void testUpdateText() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("pageref.doc");
Bookmark bookmark = doc.getBookmarks().getBookmark(0);
Range range = new Range(bookmark.getStart(), bookmark.getEnd(), doc);
range.replaceText("destination", "1destin2ation3");
bookmark = doc.getBookmarks().getBookmark(0);
assertEquals("userref", bookmark.getName());
assertEquals(27, bookmark.getStart());
assertEquals(41, bookmark.getEnd());
}
Aggregations