use of org.apache.poi.hwpf.HWPFDocument 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());
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestBookmarksTables method test.
public void test() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("pageref.doc");
Bookmarks bookmarks = doc.getBookmarks();
assertEquals(1, bookmarks.getBookmarksCount());
Bookmark bookmark = bookmarks.getBookmark(0);
assertEquals("userref", bookmark.getName());
assertEquals(27, bookmark.getStart());
assertEquals(38, bookmark.getEnd());
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestBookmarksTables method testReplaceTextBefore.
public void testReplaceTextBefore() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("pageref.doc");
Bookmark bookmark = doc.getBookmarks().getBookmark(0);
Range range = new Range(bookmark.getStart(), bookmark.getEnd(), doc);
range.replaceText("1destin2ation3", false);
bookmark = doc.getBookmarks().getBookmark(0);
assertEquals("userref", bookmark.getName());
assertEquals(27, bookmark.getStart());
assertEquals(41, bookmark.getEnd());
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestSavedByTable method testReadWrite.
/**
* Tests reading in the entries, comparing them against the expected
* entries. Then tests writing the document out and reading the entries yet
* again.
*
* @throws Exception if an unexpected error occurs.
*/
@Test
public void testReadWrite() throws IOException {
// This document is widely available on the internet as "blair.doc".
// I tried stripping the content and saving the document but my version
// of Word (from Office XP) strips this table out.
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("saved-by-table.doc");
// Check what we just read.
assertEquals("List of saved-by entries was not as expected", expected, doc.getSavedByTable().getEntries());
// Now write the entire document out, and read it back in...
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
doc.write(byteStream);
InputStream copyStream = new ByteArrayInputStream(byteStream.toByteArray());
doc.close();
HWPFDocument copy = new HWPFDocument(copyStream);
// And check again.
assertEquals("List of saved-by entries was incorrect after writing", expected, copy.getSavedByTable().getEntries());
copy.close();
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestLists method testMultiLevelLists.
public void testMultiLevelLists() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Lists.doc");
Range r = doc.getRange();
assertEquals(40, r.numParagraphs());
assertEquals("Multi-level un-ordered list:\r", r.getParagraph(12).text());
assertEquals("ML 1:1\r", r.getParagraph(13).text());
assertEquals("ML 1:2\r", r.getParagraph(14).text());
assertEquals("ML 2:1\r", r.getParagraph(15).text());
assertEquals("ML 2:2\r", r.getParagraph(16).text());
assertEquals("ML 2:3\r", r.getParagraph(17).text());
assertEquals("ML 3:1\r", r.getParagraph(18).text());
assertEquals("ML 4:1\r", r.getParagraph(19).text());
assertEquals("ML 5:1\r", r.getParagraph(20).text());
assertEquals("ML 5:2\r", r.getParagraph(21).text());
assertEquals("ML 2:4\r", r.getParagraph(22).text());
assertEquals("ML 1:3\r", r.getParagraph(23).text());
assertEquals("Multi-level ordered list:\r", r.getParagraph(24).text());
assertEquals("OL 1\r", r.getParagraph(25).text());
assertEquals("OL 2\r", r.getParagraph(26).text());
assertEquals("OL 2.1\r", r.getParagraph(27).text());
assertEquals("OL 2.2\r", r.getParagraph(28).text());
assertEquals("OL 2.2.1\r", r.getParagraph(29).text());
assertEquals("OL 2.2.2\r", r.getParagraph(30).text());
assertEquals("OL 2.2.2.1\r", r.getParagraph(31).text());
assertEquals("OL 2.2.3\r", r.getParagraph(32).text());
assertEquals("OL 3\r", r.getParagraph(33).text());
assertEquals("Finally we want some indents, to tell the difference\r", r.getParagraph(34).text());
for (int i = 12; i <= 34; i++) {
assertEquals(9, r.getParagraph(12).getLvl());
}
assertEquals(0, r.getParagraph(12).getIlvl());
assertEquals(0, r.getParagraph(13).getIlvl());
assertEquals(0, r.getParagraph(14).getIlvl());
assertEquals(1, r.getParagraph(15).getIlvl());
assertEquals(1, r.getParagraph(16).getIlvl());
assertEquals(1, r.getParagraph(17).getIlvl());
assertEquals(2, r.getParagraph(18).getIlvl());
assertEquals(3, r.getParagraph(19).getIlvl());
assertEquals(4, r.getParagraph(20).getIlvl());
assertEquals(4, r.getParagraph(21).getIlvl());
assertEquals(1, r.getParagraph(22).getIlvl());
assertEquals(0, r.getParagraph(23).getIlvl());
assertEquals(0, r.getParagraph(24).getIlvl());
assertEquals(0, r.getParagraph(25).getIlvl());
assertEquals(0, r.getParagraph(26).getIlvl());
assertEquals(1, r.getParagraph(27).getIlvl());
assertEquals(1, r.getParagraph(28).getIlvl());
assertEquals(2, r.getParagraph(29).getIlvl());
assertEquals(2, r.getParagraph(30).getIlvl());
assertEquals(3, r.getParagraph(31).getIlvl());
assertEquals(2, r.getParagraph(32).getIlvl());
assertEquals(0, r.getParagraph(33).getIlvl());
assertEquals(0, r.getParagraph(34).getIlvl());
}
Aggregations