use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestWordExtractor method testWithFooter.
@Test
public void testWithFooter() throws IOException {
// Non-unicode
HWPFDocument doc1 = HWPFTestDataSamples.openSampleFile("ThreeColHeadFoot.doc");
WordExtractor extractor1 = new WordExtractor(doc1);
assertEquals("Footer Left\tFooter Middle Footer Right\n", extractor1.getFooterText());
assertContains(extractor1.getText(), "Footer Left");
extractor1.close();
doc1.close();
// Unicode
HWPFDocument doc2 = HWPFTestDataSamples.openSampleFile("HeaderFooterUnicode.doc");
WordExtractor extractor2 = new WordExtractor(doc2);
assertEquals("The footer, with Molière, has Unicode in it.\n", extractor2.getFooterText());
assertContains(extractor2.getText(), "The footer, with");
extractor2.close();
doc2.close();
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestBug47563 method test.
private void test(int rows, int columns) throws Exception {
// POI apparently can't create a document from scratch,
// so we need an existing empty dummy document
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("empty.doc");
Range range = doc.getRange();
range.sanityCheck();
Table table = range.insertTableBefore((short) columns, rows);
table.sanityCheck();
for (int rowIdx = 0; rowIdx < table.numRows(); rowIdx++) {
TableRow row = table.getRow(rowIdx);
row.sanityCheck();
System.out.println("row " + rowIdx);
for (int colIdx = 0; colIdx < row.numCells(); colIdx++) {
TableCell cell = row.getCell(colIdx);
cell.sanityCheck();
System.out.println("column " + colIdx + ", num paragraphs " + cell.numParagraphs());
Paragraph par = cell.getParagraph(0);
par.sanityCheck();
par.insertBefore("" + (rowIdx * row.numCells() + colIdx));
par.sanityCheck();
row.sanityCheck();
table.sanityCheck();
range.sanityCheck();
}
}
String text = range.text();
int mustBeAfter = 0;
for (int i = 0; i < rows * columns; i++) {
int next = text.indexOf(Integer.toString(i), mustBeAfter);
assertTrue("Test with " + rows + "/" + columns + ": Should not find " + i + " but found it at " + next + " in " + text, next != -1);
mustBeAfter = next;
}
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestBug49820 method test.
public void test() throws IOException {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug49820.doc");
Range documentRange = doc.getRange();
StyleSheet styleSheet = doc.getStyleSheet();
// JUnit asserts
assertLevels(documentRange, styleSheet, 0, 0, 0);
assertLevels(documentRange, styleSheet, 1, 1, 1);
assertLevels(documentRange, styleSheet, 2, 2, 2);
assertLevels(documentRange, styleSheet, 3, 3, 3);
assertLevels(documentRange, styleSheet, 4, 4, 4);
assertLevels(documentRange, styleSheet, 5, 5, 5);
assertLevels(documentRange, styleSheet, 6, 6, 6);
assertLevels(documentRange, styleSheet, 7, 7, 7);
assertLevels(documentRange, styleSheet, 8, 8, 8);
assertLevels(documentRange, styleSheet, 9, 9, 9);
assertLevels(documentRange, styleSheet, 10, 9, 0);
assertLevels(documentRange, styleSheet, 11, 9, 4);
// output to console
/*for (int i=0; i<documentRange.numParagraphs(); i++) {
Paragraph par = documentRange.getParagraph(i);
int styleLvl = styleSheet.getParagraphStyle(par.getStyleIndex()).getLvl();
int parLvl = par.getLvl();
System.out.println("Style level: " + styleLvl + ", paragraph level: " + parLvl + ", text: " + par.text());
}*/
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestTextPieceTable method testAsciiParts.
/**
* Check that we do the positions correctly when working with pure-ascii
*/
@Test
public void testAsciiParts() throws Exception {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("ThreeColHeadFoot.doc");
TextPieceTable tbl = doc.getTextTable();
// All ascii, so stored in one big lump
assertEquals(1, tbl.getTextPieces().size());
TextPiece tp = tbl.getTextPieces().get(0);
assertEquals(0, tp.getStart());
assertEquals(339, tp.getEnd());
assertEquals(339, tp.characterLength());
assertEquals(339, tp.bytesLength());
assertStartsWith(tp.getStringBuilder().toString(), "This is a sample word document");
// Save and re-load
HWPFDocument docB = saveAndReload(doc);
tbl = docB.getTextTable();
assertEquals(1, tbl.getTextPieces().size());
tp = tbl.getTextPieces().get(0);
assertEquals(0, tp.getStart());
assertEquals(339, tp.getEnd());
assertEquals(339, tp.characterLength());
assertEquals(339, tp.bytesLength());
assertStartsWith(tp.getStringBuilder().toString(), "This is a sample word document");
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestPictures method testPicturesWithTable.
@Test
public void testPicturesWithTable() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug44603.doc");
List<Picture> pics = doc.getPicturesTable().getAllPictures();
assertEquals(2, pics.size());
}
Aggregations