use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestBugs method test57603SevenRowTable.
@Test(expected = ArrayIndexOutOfBoundsException.class)
public void test57603SevenRowTable() throws Exception {
HWPFDocument hwpfDocument = HWPFTestDataSamples.openSampleFile("57603-seven_columns.doc");
HWPFDocument hwpfDocument2 = HWPFTestDataSamples.writeOutAndReadBack(hwpfDocument);
assertNotNull(hwpfDocument2);
hwpfDocument2.close();
hwpfDocument.close();
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestBugs method test47286.
/**
* [FAILING] Bug 47286 - Word documents saves in wrong format if source
* contains form elements
*/
@SuppressWarnings("deprecation")
@Test
public void test47286() throws IOException {
// Fetch the current text
HWPFDocument doc1 = HWPFTestDataSamples.openSampleFile("Bug47286.doc");
WordExtractor wordExtractor = new WordExtractor(doc1);
final String text1;
try {
text1 = wordExtractor.getText().trim();
} finally {
wordExtractor.close();
doc1.close();
}
// Re-load, then re-save and re-check
doc1 = HWPFTestDataSamples.openSampleFile("Bug47286.doc");
HWPFDocument doc2 = HWPFTestDataSamples.writeOutAndReadBack(doc1);
WordExtractor wordExtractor2 = new WordExtractor(doc2);
final String text2;
try {
text2 = wordExtractor2.getText().trim();
} finally {
wordExtractor2.close();
doc1.close();
}
// the text in the saved document has some differences in line
// separators but we tolerate that
assertEqualsIgnoreNewline(text1.replaceAll("\n", ""), text2.replaceAll("\n", ""));
assertEquals(doc1.getCharacterTable().getTextRuns().size(), doc2.getCharacterTable().getTextRuns().size());
List<PlexOfField> expectedFields = doc1.getFieldsTables().getFieldsPLCF(FieldsDocumentPart.MAIN);
List<PlexOfField> actualFields = doc2.getFieldsTables().getFieldsPLCF(FieldsDocumentPart.MAIN);
assertEquals(expectedFields.size(), actualFields.size());
assertTableStructures(doc1.getRange(), doc2.getRange());
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestWordExtractor method testWithHeader.
@Test
public void testWithHeader() throws IOException {
// Non-unicode
HWPFDocument doc1 = HWPFTestDataSamples.openSampleFile("ThreeColHeadFoot.doc");
WordExtractor extractor1 = new WordExtractor(doc1);
assertEquals("First header column!\tMid header Right header!\n", extractor1.getHeaderText());
assertContains(extractor1.getText(), "First header column!");
extractor1.close();
doc1.close();
// Unicode
HWPFDocument doc2 = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc");
WordExtractor extractor2 = new WordExtractor(doc2);
assertEquals("This is a simple header, with a € euro symbol in it.\n\n", extractor2.getHeaderText());
assertContains(extractor2.getText(), "This is a simple header");
extractor2.close();
doc2.close();
}
use of org.apache.poi.hwpf.HWPFDocument 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.HWPFDocument 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());
}
Aggregations