Package org.openxml4j.opc

Examples of org.openxml4j.opc.Package


        File.separator + "IllustrativeCases.docx"
    );
  }

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


        File.separator + "sample.pptx"
    );
  }

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

        File.separator + "sample-beta.xlsx"
    );
  }
 
  public void testContainsMainContentType() throws Exception {
    Package pack = HXFDocument.openPackage(sampleFile);
   
    boolean found = false;
    for(PackagePart part : pack.getParts()) {
      if(part.getContentType().equals(HSSFXML.MAIN_CONTENT_TYPE)) {
        found = true;
      }
      System.out.println(part);
    }
View Full Code Here

  private void buildTable(String inputFile, String outputFile) {
    File destFile = new File(outputFile);

    try {
      Package pack = Package.open(inputFile, PackageAccess.READ_WRITE);
      WordDocument docx = new WordDocument(pack);

      TableDescription tableDesc = buildTestData();
      // ADD TABLE TO DOC
      docx.appendTable(tableDesc);
View Full Code Here


  protected void setUp() throws Exception {
    if (workbook == null) {
      String filePath = System.getProperty("HSSF.testdata.path")+ "/" + SS.FILENAME;
      Package pkg = Package.open(filePath);
      workbook = new XSSFWorkbook( pkg );
      sheet = workbook.getSheetAt( 0 );
      }
    _functionFailureCount = 0;
    _functionSuccessCount = 0;
View Full Code Here

    public void write(OutputStream stream) throws IOException {

        try {
            // Create a package referring the temp file.
            Package pkg = Package.create(stream);
            // Main part
            PackagePartName corePartName = PackagingURIHelper.createPartName("/xl/workbook.xml");
            // Create main part relationship
            pkg.addRelationship(corePartName, TargetMode.INTERNAL, PackageRelationshipTypes.CORE_DOCUMENT, "rId1");
            // Create main document part
            PackagePart corePart = pkg.createPart(corePartName, WORKBOOK.getContentType());
            OutputStream out;

            XmlOptions xmlOptions = new XmlOptions();
            // Requests use of whitespace for easier reading
            xmlOptions.setSavePrettyPrint();
            xmlOptions.setSaveOuter();
            xmlOptions.setUseDefaultNamespace();
           
            // Write out our sheets, updating the references
            //  to them in the main workbook as we go
            for (int i=0 ; i < this.getNumberOfSheets(); i++) {
              int sheetNumber = (i+1);
              XSSFSheet sheet = (XSSFSheet) this.getSheetAt(i);
                PackagePartName partName = PackagingURIHelper.createPartName(
                    WORKSHEET.getFileName(sheetNumber));
                PackageRelationship rel =
                   corePart.addRelationship(partName, TargetMode.INTERNAL, WORKSHEET.getRelation(), "rSheet" + sheetNumber);
                PackagePart part = pkg.createPart(partName, WORKSHEET.getContentType());
                
                // XXX This should not be needed, but apparently the setSaveOuter call above does not work in XMLBeans 2.2
                xmlOptions.setSaveSyntheticDocumentElement(new QName(CTWorksheet.type.getName().getNamespaceURI(), "worksheet"));
                sheet.save(part, xmlOptions);
                
                // Update our internal reference for the package part
                workbook.getSheets().getSheetArray(i).setId(rel.getId());
                workbook.getSheets().getSheetArray(i).setSheetId(sheetNumber);
               
                // If our sheet has comments, then write out those
                if(sheet.hasComments()) {
                  CommentsTable ct = (CommentsTable)sheet.getCommentsSourceIfExists();
                    PackagePartName ctName = PackagingURIHelper.createPartName(
                        SHEET_COMMENTS.getFileName(sheetNumber));
                    part.addRelationship(ctName, TargetMode.INTERNAL, SHEET_COMMENTS.getRelation(), "rComments");
                    PackagePart ctPart = pkg.createPart(ctName, SHEET_COMMENTS.getContentType());
                   
                    out = ctPart.getOutputStream();
                    ct.writeTo(out);
                    out.close();
                }
            }
            
            // Write shared strings and styles
            if(sharedStringSource != null) {
               SharedStringsTable sst = (SharedStringsTable)sharedStringSource;
               SHARED_STRINGS.save(sst, corePart);
            }
            if(stylesSource != null) {
               StylesTable st = (StylesTable)stylesSource;
               STYLES.save(st, corePart);
            }
           
            // Named ranges
            if(namedRanges.size() > 0) {
              CTDefinedNames names = CTDefinedNames.Factory.newInstance();
              CTDefinedName[] nr = new CTDefinedName[namedRanges.size()];
              for(int i=0; i<namedRanges.size(); i++) {
                nr[i] = namedRanges.get(i).getCTName();
              }
              names.setDefinedNameArray(nr);
              workbook.setDefinedNames(names);
            } else {
              if(workbook.isSetDefinedNames()) {
                workbook.setDefinedNames(null);
              }
            }

            // Now we can write out the main Workbook, with
            //  the correct references to the other parts
            out = corePart.getOutputStream();
            // XXX This should not be needed, but apparently the setSaveOuter call above does not work in XMLBeans 2.2
            xmlOptions.setSaveSyntheticDocumentElement(new QName(CTWorkbook.type.getName().getNamespaceURI(), "workbook"));
            workbook.save(out, xmlOptions);
            out.close();
            
            //  All done
            pkg.close();
        } catch (InvalidFormatException e) {
            // TODO: replace with more meaningful exception
            throw new RuntimeException(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 = 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

        File.separator + "sample.pptx"
    ).toString();
  }

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

/**
* Various things from the how-to documentation
*/
public class FromHowTo {
  public void processOneSheet(String filename) throws Exception {
    Package pkg = Package.open(filename);
    XSSFReader r = new XSSFReader( pkg );
    SharedStringsTable sst = r.getSharedStringsTable();

    XMLReader parser = fetchSheetParser(sst);

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.