Search in sources :

Example 1 with HWPFOldDocument

use of org.apache.poi.hwpf.HWPFOldDocument in project poi by apache.

the class TestBugs method test57843.

@Test(expected = ArrayIndexOutOfBoundsException.class)
public void test57843() throws IOException {
    File f = POIDataSamples.getDocumentInstance().getFile("57843.doc");
    POIFSFileSystem fs = new POIFSFileSystem(f, true);
    try {
        HWPFOldDocument doc = new HWPFOldDocument(fs);
        assertNotNull(doc);
        doc.close();
    } finally {
        fs.close();
    }
}
Also used : HWPFOldDocument(org.apache.poi.hwpf.HWPFOldDocument) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) File(java.io.File) Test(org.junit.Test)

Example 2 with HWPFOldDocument

use of org.apache.poi.hwpf.HWPFOldDocument in project poi by apache.

the class TestHWPFOldDocument method testWord6Sections2.

/**
     * Another word document with sections, this time with a few more section
     * properties set on it
     */
@Test
public void testWord6Sections2() throws IOException {
    HWPFOldDocument doc = HWPFTestDataSamples.openOldSampleFile("Word6_sections2.doc");
    assertEquals(1, doc.getRange().numSections());
    assertEquals(57, doc.getRange().numParagraphs());
    assertEquals("\r", doc.getRange().getParagraph(0).text());
    assertEquals("STATEMENT  OF  INSOLVENCY  PRACTICE  10  (SCOTLAND)\r", doc.getRange().getParagraph(1).text());
    doc.close();
}
Also used : HWPFOldDocument(org.apache.poi.hwpf.HWPFOldDocument) Test(org.junit.Test)

Example 3 with HWPFOldDocument

use of org.apache.poi.hwpf.HWPFOldDocument in project poi by apache.

the class TestHWPFOldDocument method testCodePageBug50955.

@Test
public void testCodePageBug50955() throws IOException {
    //windows 1251
    HWPFOldDocument doc = HWPFTestDataSamples.openOldSampleFile("Bug50955.doc");
    Word6Extractor ex = new Word6Extractor(doc);
    StringBuilder sb = new StringBuilder();
    for (String p : ex.getParagraphText()) {
        sb.append(p);
    }
    //Greetings!
    assertContains(sb.toString(), "привет");
    ex.close();
    doc.close();
}
Also used : HWPFOldDocument(org.apache.poi.hwpf.HWPFOldDocument) Word6Extractor(org.apache.poi.hwpf.extractor.Word6Extractor) Test(org.junit.Test)

Example 4 with HWPFOldDocument

use of org.apache.poi.hwpf.HWPFOldDocument in project poi by apache.

the class TestHWPFOldDocument method testWord95hwpfOld.

@Test
public void testWord95hwpfOld() throws IOException {
    // Open
    HWPFOldDocument doc = HWPFTestDataSamples.openOldSampleFile("Word95.doc");
    // Check
    assertEquals(1, doc.getRange().numSections());
    assertEquals(7, doc.getRange().numParagraphs());
    assertEquals("The quick brown fox jumps over the lazy dog\r", doc.getRange().getParagraph(0).text());
    assertEquals("\r", doc.getRange().getParagraph(1).text());
    assertEquals("Paragraph 2\r", doc.getRange().getParagraph(2).text());
    assertEquals("\r", doc.getRange().getParagraph(3).text());
    assertEquals("Paragraph 3. Has some RED text and some " + "BLUE BOLD text in it.\r", doc.getRange().getParagraph(4).text());
    assertEquals("\r", doc.getRange().getParagraph(5).text());
    assertEquals("Last (4th) paragraph.\r", doc.getRange().getParagraph(6).text());
    assertEquals(1, doc.getRange().getParagraph(0).numCharacterRuns());
    assertEquals(1, doc.getRange().getParagraph(1).numCharacterRuns());
    assertEquals(1, doc.getRange().getParagraph(2).numCharacterRuns());
    assertEquals(1, doc.getRange().getParagraph(3).numCharacterRuns());
    // Normal, red, normal, blue+bold, normal
    assertEquals(5, doc.getRange().getParagraph(4).numCharacterRuns());
    assertEquals(1, doc.getRange().getParagraph(5).numCharacterRuns());
    // Normal, superscript for 4th, normal
    assertEquals(3, doc.getRange().getParagraph(6).numCharacterRuns());
    doc.close();
}
Also used : HWPFOldDocument(org.apache.poi.hwpf.HWPFOldDocument) Test(org.junit.Test)

Example 5 with HWPFOldDocument

use of org.apache.poi.hwpf.HWPFOldDocument in project poi by apache.

the class TestHWPFOldDocument method testOldFontTableEncoding.

@Test
public void testOldFontTableEncoding() throws IOException {
    HWPFOldDocument doc = HWPFTestDataSamples.openOldSampleFile("Bug51944.doc");
    OldFontTable oldFontTable = doc.getOldFontTable();
    assertEquals(5, oldFontTable.getFontNames().length);
    assertEquals("細明體", oldFontTable.getFontNames()[0].getMainFontName());
    assertEquals(HwmfFont.WmfCharset.CHINESEBIG5_CHARSET.getCharset(), Charset.forName("Big5"));
    assertEquals("Times New Roman", oldFontTable.getFontNames()[1].getMainFontName());
    doc.close();
}
Also used : HWPFOldDocument(org.apache.poi.hwpf.HWPFOldDocument) OldFontTable(org.apache.poi.hwpf.model.OldFontTable) Test(org.junit.Test)

Aggregations

HWPFOldDocument (org.apache.poi.hwpf.HWPFOldDocument)15 Test (org.junit.Test)12 Word6Extractor (org.apache.poi.hwpf.extractor.Word6Extractor)6 OldFontTable (org.apache.poi.hwpf.model.OldFontTable)2 File (java.io.File)1 HWPFDocument (org.apache.poi.hwpf.HWPFDocument)1 StyleDescription (org.apache.poi.hwpf.model.StyleDescription)1 SprmIterator (org.apache.poi.hwpf.sprm.SprmIterator)1 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)1 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)1