Package org.openxml4j.opc

Examples of org.openxml4j.opc.Package


    /**
     * Create a new SpreadsheetML package and setup the default minimal content
     */
    protected static Package newPackage() {
        try {
            Package pkg = Package.create(PackageHelper.createTempFile());
            // Main part
            PackagePartName corePartName = PackagingURIHelper.createPartName(XWPFRelation.DOCUMENT.getDefaultFileName());
            // Create main part relationship
            pkg.addRelationship(corePartName, TargetMode.INTERNAL, PackageRelationshipTypes.CORE_DOCUMENT);
            // Create main document part
            pkg.createPart(corePartName, XWPFRelation.DOCUMENT.getContentType());

            pkg.getPackageProperties().setCreatorProperty("Apache POI");

            return pkg;
        } catch (Exception e){
            throw new POIXMLException(e);
        }
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 = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
    assertNotNull(workbook.getSharedStringSource());
    assertNotNull(workbook.getStylesSource());
   
    // And check a few low level bits too
    Package pkg = Package.open(HSSFTestDataSamples.openSampleFileStream("Formatting.xlsx"));
    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

    assertTrue(sampleFile.exists());
    assertTrue(complexFile.exists());
  }

  public void testContainsMainContentType() throws Exception {
    Package pack = POIXMLDocument.openPackage(sampleFile.toString());
   
    boolean found = false;
    for(PackagePart part : pack.getParts()) {
      if(part.getContentType().equals(XWPFRelation.DOCUMENT.getContentType())) {
        found = true;
      }
      System.out.println(part);
    }
View Full Code Here

*/
public class XSSFTestDataSamples {
  public static final XSSFWorkbook openSampleWorkbook(String sampleName) {
    InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleName);
    try {
      Package pkg = Package.open(is);
      return new XSSFWorkbook(pkg);
    } catch (InvalidFormatException e) {
      throw new RuntimeException(e);
    } catch (IOException e) {
      throw new RuntimeException(e);
View Full Code Here

                File tmp = File.createTempFile("poi-ooxml-", ".xlsx");
                tmp.deleteOnExit();
                FileOutputStream out = new FileOutputStream(tmp);
                wb.write(out);
                out.close();
          Package pkg = Package.open(tmp.getAbsolutePath());
          result = new XSSFWorkbook(pkg);
        } else {
          throw new RuntimeException("Unexpected workbook type ("
              + wb.getClass().getName() + ")");
        }
View Full Code Here

      );
  }
   
    public void testGetBits() throws Exception {
      File f = new File(dirName, "SampleSS.xlsx");
      Package pkg = Package.open(f.toString());
     
      XSSFReader r = new XSSFReader(pkg);
     
      assertNotNull(r.getWorkbookData());
      assertNotNull(r.getSharedStringsData());
View Full Code Here

      assertNotNull(r.getStylesTable());
    }
   
    public void testStyles() throws Exception {
      File f = new File(dirName, "SampleSS.xlsx");
      Package pkg = Package.open(f.toString());
     
      XSSFReader r = new XSSFReader(pkg);
     
      assertEquals(3, r.getStylesTable().getFonts().size());
      assertEquals(0, r.getStylesTable()._getNumberFormatSize());
View Full Code Here

      assertEquals(0, r.getStylesTable()._getNumberFormatSize());
    }
   
    public void testStrings() throws Exception {
      File f = new File(dirName, "SampleSS.xlsx");
      Package pkg = Package.open(f.toString());
     
      XSSFReader r = new XSSFReader(pkg);
     
      assertEquals(11, r.getSharedStringsTable().getItems().size());
      assertEquals("Test spreadsheet", new XSSFRichTextString(r.getSharedStringsTable().getEntryAt(0)).toString());
View Full Code Here

      assertEquals("Test spreadsheet", new XSSFRichTextString(r.getSharedStringsTable().getEntryAt(0)).toString());
    }
   
    public void testSheets() throws Exception {
      File f = new File(dirName, "SampleSS.xlsx");
      Package pkg = Package.open(f.toString());
     
      XSSFReader r = new XSSFReader(pkg);
      byte[] data = new byte[4096];
     
      // By r:id
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.