Package org.openxml4j.opc

Examples of org.openxml4j.opc.PackageRelationship


        try {
          ppName = PackagingURIHelper.createPartName(name);
        } catch(InvalidFormatException e) {
          throw new IllegalStateException("Can't create part with name " + name + " for " + model, e);
        }
        PackageRelationship rel =
          corePart.addRelationship(ppName, TargetMode.INTERNAL, REL);
        PackagePart part = corePart.getPackage().createPart(ppName, TYPE);
       
        OutputStream out = part.getOutputStream();
        model.writeTo(out);
        out.close();
       
    // Do children, if required
    if(model instanceof XSSFChildContainingModel) {
      XSSFChildContainingModel ccm =
        (XSSFChildContainingModel)model;
      // Loop over each child, writing it out
      int numChildren = ccm.getNumberOfChildren();
      for(int i=0; i<numChildren; i++) {
        XSSFChildContainingModel.WritableChild child =
          ccm.getChildForWriting(i);
        child.getRelation().save(
            child.getModel(),
            part,
            (i+1)
        );
      }
    }
       
        return rel.getId();
  }
View Full Code Here


     * @param ctSheet The sheet
     * @return A PackagePart, or null if no matching part found.
     * @throws InvalidFormatException
     */
    private PackagePart getPackagePart(CTSheet ctSheet) throws InvalidFormatException {
        PackageRelationship rel = this.getCorePart().getRelationship(ctSheet.getId());
        if (rel == null) {
            log.log(POILogger.WARN, "No relationship found for sheet " + ctSheet.getId() + " - core part has " + this.getCorePart().getRelationships().size() + " relations defined");
            return null;
        }
        return getTargetPart(rel);
View Full Code Here

            for (int i=0 ; i < this.getNumberOfSheets(); i++) {
              int sheetNumber = (i+1);
              XSSFSheet sheet = (XSSFSheet) this.getSheetAt(i);
                PackagePartName partName = PackagingURIHelper.createPartName(
                    XSSFRelation.WORKSHEET.getFileName(sheetNumber));
                PackageRelationship rel =
                   corePart.addRelationship(partName, TargetMode.INTERNAL, XSSFRelation.WORKSHEET.getRelation(), "rSheet" + sheetNumber);
                PackagePart part = pkg.createPart(partName, XSSFRelation.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();
View Full Code Here

    protected void initHyperlinks(PackageRelationshipCollection hyperRels) {
      if(worksheet.getHyperlinks() == null) return;
     
      // Turn each one into a XSSFHyperlink
      for(CTHyperlink hyperlink : worksheet.getHyperlinks().getHyperlinkArray()) {
        PackageRelationship hyperRel = null;
        if(hyperlink.getId() != null) {
          hyperRel = hyperRels.getRelationshipByID(hyperlink.getId());
        }
       
        hyperlinks.add(
View Full Code Here

            PackageRelationshipCollection hyperRels =
                getPackagePart().getRelationshipsByType(XSSFRelation.SHEET_HYPERLINKS.getRelation());

            // Turn each one into a XSSFHyperlink
            for(CTHyperlink hyperlink : worksheet.getHyperlinks().getHyperlinkArray()) {
                PackageRelationship hyperRel = null;
                if(hyperlink.getId() != null) {
                    hyperRel = hyperRels.getRelationshipByID(hyperlink.getId());
                }

                hyperlinks.add( new XSSFHyperlink(hyperlink, hyperRel) );
View Full Code Here

     * Generates the relation if required
     */
    protected void generateRelationIfNeeded(PackagePart sheetPart) {
        if (needsRelationToo()) {
            // Generate the relation
            PackageRelationship rel =
                    sheetPart.addExternalRelationship(location, XSSFRelation.SHEET_HYPERLINKS.getRelation());

            // Update the r:id
            ctHyperlink.setId(rel.getId());
        }
    }
View Full Code Here

     * Creates a new XSSFReader, for the given package
     */
    public XSSFReader(Package pkg) throws IOException, OpenXML4JException {
        this.pkg = pkg;

        PackageRelationship coreDocRelationship = this.pkg.getRelationshipsByType(
                PackageRelationshipTypes.CORE_DOCUMENT).getRelationship(0);

        // Get the part that holds the workbook
        workbookPart = this.pkg.getPart(coreDocRelationship);
    }
View Full Code Here

     * Returns an InputStream to read the contents of the
     *  specified Sheet.
     * @param relId The relationId of the sheet, from a r:id on the workbook
     */
    public InputStream getSheet(String relId) throws IOException, InvalidFormatException {
        PackageRelationship rel = workbookPart.getRelationship(relId);
        if(rel == null) {
            throw new IllegalArgumentException("No Sheet found with r:id " + relId);
        }

        PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
        PackagePart sheet = pkg.getPart(relName);
        if(sheet == null) {
            throw new IllegalArgumentException("No data found for Sheet with r:id " + relId);
        }
        return sheet.getInputStream();
View Full Code Here

  public InputStream getContents(PackagePart corePart) throws IOException, InvalidFormatException {
        PackageRelationshipCollection prc =
          corePart.getRelationshipsByType(_relation);
        Iterator<PackageRelationship> it = prc.iterator();
        if(it.hasNext()) {
            PackageRelationship rel = it.next();
            PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
            PackagePart part = corePart.getPackage().getPart(relName);
            return part.getInputStream();
        } else {
          log.log(POILogger.WARN, "No part " + _defaultName + " found");
          return null;
View Full Code Here

     * @param pictureIndex the index of the picture in the workbook collection of pictures,
     *                     {@link XSSFWorkbook#getAllPictures()} .
     * @return the newly created picture shape.
     */
    public XSSFPicture createPicture(XSSFClientAnchor anchor, int pictureIndex) {
        PackageRelationship rel = getDrawing().addPictureReference(pictureIndex);

        CTPicture ctShape = ctGroup.addNewPic();
        ctShape.set(XSSFPicture.prototype());

        XSSFPicture shape = new XSSFPicture(getDrawing(), ctShape);
View Full Code Here

TOP

Related Classes of org.openxml4j.opc.PackageRelationship

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.