Package org.openxml4j.opc

Examples of org.openxml4j.opc.Package


     * Check that the sheet iterator returns sheets in the logical order
     * (as they are defined in the workbook.xml)
     */
    public void testOrderOfSheets() throws Exception {
        File f = new File(dirName, "reordered_sheets.xlsx");
        Package pkg = Package.open(f.toString());

        XSSFReader r = new XSSFReader(pkg);

        String[] sheetNames = {"Sheet4", "Sheet2", "Sheet3", "Sheet1"};
        XSSFReader.SheetIterator it = (XSSFReader.SheetIterator)r.getSheetsData();
View Full Code Here


        System.getProperty("HSSF.testdata.path") +
        File.separator + "WithVariousData.xlsx"
    );
    assertTrue(xml.exists());
     
    Package pkg = Package.open(xml.toString());
    XSSFWorkbook wb = new XSSFWorkbook(pkg);
        List<POIXMLDocumentPart> rels = wb.getSheetAt(0).getRelations();
        CommentsTable ct = null;
        for(POIXMLDocumentPart p : rels) {
            if(p instanceof CommentsTable){
View Full Code Here

        OutputStream out = new FileOutputStream(file);
        workbook.write(out);
        out.close();
       
        // Check the package contains what we'd expect it to
        Package pkg = Package.open(file.toString());
        PackagePart wbRelPart =
          pkg.getPart(PackagingURIHelper.createPartName("/xl/_rels/workbook.xml.rels"));
        assertNotNull(wbRelPart);
        assertTrue(wbRelPart.isRelationshipPart());
        assertEquals(ContentTypes.RELATIONSHIPS_PART, wbRelPart.getContentType());
       
        PackagePart wbPart =
          pkg.getPart(PackagingURIHelper.createPartName("/xl/workbook.xml"));
        // Links to the three sheets, shared strings and styles
        assertTrue(wbPart.hasRelationships());
        assertEquals(5, wbPart.getRelationships().size());
       
        // Load back the XSSFWorkbook
View Full Code Here

    XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
    assertNotNull(workbook.getSharedStringSource());
    assertNotNull(workbook.getStylesSource());
   
    // And check a few low level bits too
    Package pkg = Package.open(xml.toString());
        PackagePart wbPart =
          pkg.getPart(PackagingURIHelper.createPartName("/xl/workbook.xml"));
       
        // Links to the three sheets, shared, styles and themes
        assertTrue(wbPart.hasRelationships());
        assertEquals(6, wbPart.getRelationships().size());
View Full Code Here

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    wb.write(baos);
    ByteArrayInputStream inp = new ByteArrayInputStream(
        baos.toByteArray()
    );
    Package pkg = Package.open(inp);
    return pkg;
  }
View Full Code Here

    assertFalse(wb.getNameAt(2).getCTName().isSetLocalSheetId());
    assertEquals("SheetC!$A$1", wb.getNameAt(2).getReference());
    assertEquals("SheetC", wb.getNameAt(2).getSheetName());
   
    // Save and re-load, still there
    Package nPkg = saveAndOpen(wb);
    XSSFWorkbook nwb = new XSSFWorkbook(nPkg);
    assertEquals(3, nwb.getNumberOfNames());
    assertEquals("SheetA!$A$1", nwb.getNameAt(0).getReference());
  }
View Full Code Here

 
  /**
   * We should carry vba macros over after save
   */
  public void test45431() throws Exception {
    Package pkg = Package.open(getFilePath("45431.xlsm"));
    XSSFWorkbook wb = new XSSFWorkbook(pkg);
    assertTrue(wb.isMacroEnabled());
   
    // Check the various macro related bits can be found
    PackagePart vba = pkg.getPart(
        PackagingURIHelper.createPartName("/xl/vbaProject.bin")
    );
    assertNotNull(vba);
    // And the drawing bit
    PackagePart drw = pkg.getPart(
        PackagingURIHelper.createPartName("/xl/drawings/vmlDrawing1.vml")
    );
    assertNotNull(drw);
   
   
    // Save and re-open, both still there
    Package nPkg = saveAndOpen(wb);
    XSSFWorkbook nwb = new XSSFWorkbook(nPkg);
    assertTrue(nwb.isMacroEnabled());
   
    vba = nPkg.getPart(
        PackagingURIHelper.createPartName("/xl/vbaProject.bin")
    );
    assertNotNull(vba);
    drw = nPkg.getPart(
        PackagingURIHelper.createPartName("/xl/drawings/vmlDrawing1.vml")
    );
    assertNotNull(drw);
   
    // And again, just to be sure
    nPkg = saveAndOpen(nwb);
    nwb = new XSSFWorkbook(nPkg);
    assertTrue(nwb.isMacroEnabled());
   
    vba = nPkg.getPart(
        PackagingURIHelper.createPartName("/xl/vbaProject.bin")
    );
    assertNotNull(vba);
    drw = nPkg.getPart(
        PackagingURIHelper.createPartName("/xl/drawings/vmlDrawing1.vml")
    );
    assertNotNull(drw);
   
    // For testing with excel
View Full Code Here

TOP

Related Classes of org.openxml4j.opc.Package

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.