Search in sources :

Example 46 with OPCPackage

use of org.apache.poi.openxml4j.opc.OPCPackage in project poi by apache.

the class TestXSSFBSharedStringsTable method testBasic.

@Test
public void testBasic() throws Exception {
    OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("51519.xlsb"));
    List<PackagePart> parts = pkg.getPartsByName(Pattern.compile("/xl/sharedStrings.bin"));
    assertEquals(1, parts.size());
    XSSFBSharedStringsTable rtbl = new XSSFBSharedStringsTable(parts.get(0));
    List<String> strings = rtbl.getItems();
    assertEquals(49, strings.size());
    assertEquals("コメント", rtbl.getEntryAt(0));
    assertEquals("日本オラクル", rtbl.getEntryAt(3));
    assertEquals(55, rtbl.getCount());
    assertEquals(49, rtbl.getUniqueCount());
//TODO: add in tests for phonetic runs
}
Also used : PackagePart(org.apache.poi.openxml4j.opc.PackagePart) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) Test(org.junit.Test)

Example 47 with OPCPackage

use of org.apache.poi.openxml4j.opc.OPCPackage in project poi by apache.

the class TestReadOnlySharedStringsTable method testEmptySSTOnPackageObtainedViaWorkbook.

public void testEmptySSTOnPackageObtainedViaWorkbook() throws Exception {
    XSSFWorkbook wb = new XSSFWorkbook(_ssTests.openResourceAsStream("noSharedStringTable.xlsx"));
    OPCPackage pkg = wb.getPackage();
    assertEmptySST(pkg);
    wb.close();
}
Also used : XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage)

Example 48 with OPCPackage

use of org.apache.poi.openxml4j.opc.OPCPackage in project poi by apache.

the class TestXSSFBReader method getSheets.

private List<String> getSheets(String testFileName) throws Exception {
    OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream(testFileName));
    List<String> sheetTexts = new ArrayList<String>();
    XSSFBReader r = new XSSFBReader(pkg);
    //        assertNotNull(r.getWorkbookData());
    //      assertNotNull(r.getSharedStringsData());
    assertNotNull(r.getXSSFBStylesTable());
    XSSFBSharedStringsTable sst = new XSSFBSharedStringsTable(pkg);
    XSSFBStylesTable xssfbStylesTable = r.getXSSFBStylesTable();
    XSSFBReader.SheetIterator it = (XSSFBReader.SheetIterator) r.getSheetsData();
    while (it.hasNext()) {
        InputStream is = it.next();
        String name = it.getSheetName();
        TestSheetHandler testSheetHandler = new TestSheetHandler();
        testSheetHandler.startSheet(name);
        XSSFBSheetHandler sheetHandler = new XSSFBSheetHandler(is, xssfbStylesTable, it.getXSSFBSheetComments(), sst, testSheetHandler, new DataFormatter(), false);
        sheetHandler.parse();
        testSheetHandler.endSheet();
        sheetTexts.add(testSheetHandler.toString());
    }
    return sheetTexts;
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) XSSFBStylesTable(org.apache.poi.xssf.binary.XSSFBStylesTable) XSSFBSharedStringsTable(org.apache.poi.xssf.binary.XSSFBSharedStringsTable) XSSFBSheetHandler(org.apache.poi.xssf.binary.XSSFBSheetHandler) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) DataFormatter(org.apache.poi.ss.usermodel.DataFormatter)

Example 49 with OPCPackage

use of org.apache.poi.openxml4j.opc.OPCPackage in project poi by apache.

the class TestXSSFBReader method testAbsPath.

@Test
public void testAbsPath() throws Exception {
    OPCPackage pkg = OPCPackage.open(_ssTests.openResourceAsStream("testVarious.xlsb"));
    XSSFBReader r = new XSSFBReader(pkg);
    assertEquals("C:\\Users\\tallison\\Desktop\\working\\xlsb\\", r.getAbsPathMetadata());
}
Also used : OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage) Test(org.junit.Test)

Example 50 with OPCPackage

use of org.apache.poi.openxml4j.opc.OPCPackage in project poi by apache.

the class TestXSSFReader method testShapes.

/**
     * Test text extraction from text box using getShapes()
     *
     * @throws Exception
     */
public void testShapes() throws Exception {
    OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("WithTextBox.xlsx");
    XSSFReader r = new XSSFReader(pkg);
    XSSFReader.SheetIterator it = (XSSFReader.SheetIterator) r.getSheetsData();
    String text = getShapesString(it);
    assertContains(text, "Line 1");
    assertContains(text, "Line 2");
    assertContains(text, "Line 3");
}
Also used : XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) OPCPackage(org.apache.poi.openxml4j.opc.OPCPackage)

Aggregations

OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)116 Test (org.junit.Test)54 InputStream (java.io.InputStream)29 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)25 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)21 File (java.io.File)19 IOException (java.io.IOException)17 PackagePartName (org.apache.poi.openxml4j.opc.PackagePartName)16 ByteArrayInputStream (java.io.ByteArrayInputStream)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)13 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)13 SignatureConfig (org.apache.poi.poifs.crypt.dsig.SignatureConfig)10 SignatureInfo (org.apache.poi.poifs.crypt.dsig.SignatureInfo)10 XSSFReader (org.apache.poi.xssf.eventusermodel.XSSFReader)10 OutputStream (java.io.OutputStream)9 ArrayList (java.util.ArrayList)9 FileOutputStream (java.io.FileOutputStream)8 InvalidOperationException (org.apache.poi.openxml4j.exceptions.InvalidOperationException)8 XmlException (org.apache.xmlbeans.XmlException)8 FileInputStream (java.io.FileInputStream)7