use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestLists method testWriteRead.
public void testWriteRead() throws IOException {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Lists.doc");
doc = HWPFTestDataSamples.writeOutAndReadBack(doc);
Range r = doc.getRange();
// Check a couple at random
assertEquals(4, r.getParagraph(21).getIlvl());
assertEquals(1, r.getParagraph(22).getIlvl());
assertEquals(0, r.getParagraph(23).getIlvl());
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestLists method testSpecificNumberedOrderedListFeatures.
public void testSpecificNumberedOrderedListFeatures() throws IOException {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Lists.doc");
Range r = doc.getRange();
//29 = OL 2.2.1
for (int i = 26; i < 30; i++) {
Paragraph p = r.getParagraph(i);
assertTrue(p.isInList());
HWPFList list = p.getList();
ListLevel level = list.getLVL((char) p.getIlvl());
assertFalse(level.isLegalNumbering());
assertEquals(-1, level.getRestart());
}
Paragraph p = r.getParagraph(26);
HWPFList list = p.getList();
ListLevel level = list.getLVL((char) p.getIlvl());
byte[] lvl = level.getLevelNumberingPlaceholderOffsets();
assertEquals((byte) 1, lvl[0]);
assertEquals((byte) 0, lvl[1]);
p = r.getParagraph(27);
list = p.getList();
level = list.getLVL((char) p.getIlvl());
lvl = level.getLevelNumberingPlaceholderOffsets();
assertEquals((byte) 1, lvl[0]);
assertEquals((byte) 3, lvl[1]);
p = r.getParagraph(29);
list = p.getList();
level = list.getLVL((char) p.getIlvl());
lvl = level.getLevelNumberingPlaceholderOffsets();
assertEquals((byte) 1, lvl[0]);
assertEquals((byte) 3, lvl[1]);
assertEquals((byte) 5, lvl[2]);
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestBorderCode method test.
public void test() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug49919.doc");
range = doc.getRange();
Paragraph par = findParagraph("Paragraph normal\r");
assertEquals(0, par.getLeftBorder().getBorderType());
assertEquals(0, par.getRightBorder().getBorderType());
assertEquals(0, par.getTopBorder().getBorderType());
assertEquals(0, par.getBottomBorder().getBorderType());
par = findParagraph("Paragraph with border\r");
assertEquals(18, par.getLeftBorder().getBorderType());
assertEquals(17, par.getRightBorder().getBorderType());
assertEquals(18, par.getTopBorder().getBorderType());
assertEquals(17, par.getBottomBorder().getBorderType());
assertEquals(15, par.getLeftBorder().getColor());
par = findParagraph("Paragraph with red border\r");
assertEquals(1, par.getLeftBorder().getBorderType());
assertEquals(1, par.getRightBorder().getBorderType());
assertEquals(1, par.getTopBorder().getBorderType());
assertEquals(1, par.getBottomBorder().getBorderType());
assertEquals(6, par.getLeftBorder().getColor());
par = findParagraph("Paragraph with bordered words.\r");
assertEquals(0, par.getLeftBorder().getBorderType());
assertEquals(0, par.getRightBorder().getBorderType());
assertEquals(0, par.getTopBorder().getBorderType());
assertEquals(0, par.getBottomBorder().getBorderType());
assertEquals(3, par.numCharacterRuns());
CharacterRun chr = par.getCharacterRun(0);
assertEquals(0, chr.getBorder().getBorderType());
chr = par.getCharacterRun(1);
assertEquals(1, chr.getBorder().getBorderType());
assertEquals(0, chr.getBorder().getColor());
chr = par.getCharacterRun(2);
assertEquals(0, chr.getBorder().getBorderType());
while (pos < range.numParagraphs() - 1) {
par = range.getParagraph(pos++);
if (par.isInTable())
break;
}
assertEquals(true, par.isInTable());
Table tab = range.getTable(par);
// Border could be defined for the entire row, or for each cell, with the same visual appearance.
assertEquals(2, tab.numRows());
TableRow row = tab.getRow(0);
assertEquals(1, row.getLeftBorder().getBorderType());
assertEquals(1, row.getRightBorder().getBorderType());
assertEquals(1, row.getTopBorder().getBorderType());
assertEquals(1, row.getBottomBorder().getBorderType());
assertEquals(2, row.numCells());
TableCell cell = row.getCell(1);
assertEquals(3, cell.getBrcTop().getBorderType());
row = tab.getRow(1);
cell = row.getCell(0);
// 255 clears border inherited from row
assertEquals(255, cell.getBrcBottom().getBorderType());
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestBug46610 method runExtract.
private static String runExtract(String sampleName) throws Exception {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile(sampleName);
StringBuffer out = new StringBuffer();
Range globalRange = doc.getRange();
for (int i = 0; i < globalRange.numParagraphs(); i++) {
Paragraph p = globalRange.getParagraph(i);
out.append(p.text());
out.append("\n");
for (int j = 0; j < p.numCharacterRuns(); j++) {
CharacterRun characterRun = p.getCharacterRun(j);
characterRun.text();
}
doc.close();
}
return out.toString();
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestWordExtractor method testEndnote.
@Test
public void testEndnote() throws IOException {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("footnote.doc");
WordExtractor extractor = new WordExtractor(doc);
assertExtractedContains(extractor.getEndnoteText(), "TestEndnote");
// msonfcLCRoman
assertEquals(0x02, doc.getRange().getSection(0).getEndnoteNumberingFormat());
// rncCont
assertEquals(0x00, doc.getRange().getSection(0).getEndnoteRestartQualifier());
assertEquals(0, doc.getRange().getSection(0).getEndnoteNumberingOffset());
assertEquals(1, doc.getEndnotes().getNotesCount());
extractor.close();
doc.close();
}
Aggregations