org.apache.poi.xssf.usermodel.XSSFRelation.getRelation()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(122)

本文整理了Java中org.apache.poi.xssf.usermodel.XSSFRelation.getRelation()方法的一些代码示例,展示了XSSFRelation.getRelation()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XSSFRelation.getRelation()方法的具体详情如下:
包路径:org.apache.poi.xssf.usermodel.XSSFRelation
类名称:XSSFRelation
方法名:getRelation

XSSFRelation.getRelation介绍

暂无

代码示例

代码示例来源:origin: org.apache.poi/poi-ooxml

private void loadUrlsFromSheetRels(PackagePart sheetPart) {
  try {
    for (PackageRelationship rel : sheetPart.getRelationshipsByType(XSSFRelation.SHEET_HYPERLINKS.getRelation())) {
      relIdToHyperlink.put(rel.getId(), rel.getTargetURI().toString());
    }
  } catch (InvalidFormatException e) {
    //swallow
  }
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Get the document's embedded files.
 */
@Override
public List<PackagePart> getAllEmbeddedParts() throws OpenXML4JException {
  List<PackagePart> embedds = new LinkedList<>();
  for(XSSFSheet sheet : sheets){
    // Get the embeddings for the workbook
    for(PackageRelationship rel : sheet.getPackagePart().getRelationshipsByType(XSSFRelation.OLEEMBEDDINGS.getRelation())) {
      embedds.add( sheet.getPackagePart().getRelatedPart(rel) );
    }
    for(PackageRelationship rel : sheet.getPackagePart().getRelationshipsByType(XSSFRelation.PACKEMBEDDINGS.getRelation())) {
      embedds.add( sheet.getPackagePart().getRelatedPart(rel) );
    }
  }
  return embedds;
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Generates the relation if required
 */
protected void generateRelationIfNeeded(PackagePart sheetPart) {
  if (_externalRel == null && needsRelationToo()) {
    // Generate the relation
    PackageRelationship rel =
        sheetPart.addExternalRelationship(_location, XSSFRelation.SHEET_HYPERLINKS.getRelation());
    // Update the r:id
    _ctHyperlink.setId(rel.getId());
  }
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
   * @return the list of all Tables that provide a map rule to this mapping
   */
  public List<XSSFTable> getRelatedTables() {
    List<XSSFTable> tables = new ArrayList<>();
    for (Sheet sheet : mapInfo.getWorkbook()) {
      for (RelationPart rp : ((XSSFSheet)sheet).getRelationParts()) {
        if (rp.getRelationship().getRelationshipType().equals(XSSFRelation.TABLE.getRelation())) {
          XSSFTable table = rp.getDocumentPart();
          if (table.mapsTo(ctMap.getID())) {
            tables.add(table);
          }
        }
      }
    }

    return tables;
  }
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Read hyperlink relations, link them with CTHyperlink beans in this worksheet
 * and initialize the internal array of XSSFHyperlink objects
 */
private void initHyperlinks() {
  hyperlinks = new ArrayList<>();
  if(!worksheet.isSetHyperlinks()) {
    return;
  }
  try {
    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) );
    }
  } catch (InvalidFormatException e){
    throw new POIXMLException(e);
  }
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Returns the shapes associated with this sheet,
 * an empty list or null if there is an exception
 */
public List<XSSFShape> getShapes() {
  PackagePart sheetPkg = getSheetPart();
  List<XSSFShape> shapes = new LinkedList<>();
  // Do we have a comments relationship? (Only ever one if so)
  try {
    PackageRelationshipCollection drawingsList = sheetPkg.getRelationshipsByType(XSSFRelation.DRAWINGS.getRelation());
    for (int i = 0; i < drawingsList.size(); i++) {
      PackageRelationship drawings = drawingsList.getRelationship(i);
      PackagePartName drawingsName = PackagingURIHelper.createPartName(drawings.getTargetURI());
      PackagePart drawingsPart = sheetPkg.getPackage().getPart(drawingsName);
      if (drawingsPart == null) {
        //parts can go missing; Excel ignores them silently -- TIKA-2134
        LOGGER.log(POILogger.WARN, "Missing drawing: " + drawingsName + ". Skipping it.");
        continue;
      }
      XSSFDrawing drawing = new XSSFDrawing(drawingsPart);
      shapes.addAll(drawing.getShapes());
    }
  } catch (XmlException|InvalidFormatException|IOException e) {
    LOGGER.log(POILogger.WARN, e);
    return null;
  }
  return shapes;
}

代码示例来源:origin: org.apache.poi/poi-ooxml

/**
 * Returns the comments associated with this sheet,
 * or null if there aren't any
 */
public CommentsTable getSheetComments() {
  PackagePart sheetPkg = getSheetPart();
  // Do we have a comments relationship? (Only ever one if so)
  try {
    PackageRelationshipCollection commentsList =
        sheetPkg.getRelationshipsByType(XSSFRelation.SHEET_COMMENTS.getRelation());
    if (commentsList.size() > 0) {
      PackageRelationship comments = commentsList.getRelationship(0);
      PackagePartName commentsName = PackagingURIHelper.createPartName(comments.getTargetURI());
      PackagePart commentsPart = sheetPkg.getPackage().getPart(commentsName);
      return new CommentsTable(commentsPart);
    }
  } catch (InvalidFormatException|IOException e) {
    LOGGER.log(POILogger.WARN, e);
    return null;
  }
  return null;
}

代码示例来源:origin: org.apache.poi/poi-ooxml

public XSSFBCommentsTable getXSSFBSheetComments() {
  PackagePart sheetPkg = getSheetPart();
  // Do we have a comments relationship? (Only ever one if so)
  try {
    PackageRelationshipCollection commentsList =
        sheetPkg.getRelationshipsByType(XSSFRelation.SHEET_COMMENTS.getRelation());
    if (commentsList.size() > 0) {
      PackageRelationship comments = commentsList.getRelationship(0);
      if (comments == null || comments.getTargetURI() == null) {
        return null;
      }
      PackagePartName commentsName = PackagingURIHelper.createPartName(comments.getTargetURI());
      PackagePart commentsPart = sheetPkg.getPackage().getPart(commentsName);
      return new XSSFBCommentsTable(commentsPart.getInputStream());
    }
  } catch (InvalidFormatException | IOException e) {
    return null;
  }
  return null;
}

代码示例来源:origin: org.apache.poi/poi-ooxml

TargetMode.INTERNAL, XSSFRelation.PIVOT_CACHE_DEFINITION.getRelation());

代码示例来源:origin: apache/tika

protected void extractHyperLinks(PackagePart sheetPart, XHTMLContentHandler xhtml) throws SAXException {
  try {
    for (PackageRelationship rel : sheetPart.getRelationshipsByType(XSSFRelation.SHEET_HYPERLINKS.getRelation())) {
      xhtml.startElement("a", "href", rel.getTargetURI().toString());
      xhtml.characters(rel.getTargetURI().toString());
      xhtml.endElement("a");
    }
  } catch (InvalidFormatException e) {
    //swallow
  }
}

代码示例来源:origin: apache/tika

handleEmbeddedFile(target, handler, sourceDesc + rel.getId());
  handledTarget.add(targetURI.toString());
} else if (XSSFRelation.VBA_MACROS.getRelation().equals(type)) {
  handleMacros(target, handler);
  handledTarget.add(targetURI.toString());

代码示例来源:origin: apache/tika

protected void addDrawingHyperLinks(PackagePart sheetPart) {
  try {
    for (PackageRelationship rel : sheetPart.getRelationshipsByType(XSSFRelation.DRAWINGS.getRelation())) {
      if (rel.getTargetMode() == TargetMode.INTERNAL) {
        PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
        PackagePart part = rel.getPackage().getPart(relName);
        //parts can go missing, and Excel quietly ignores missing images -- TIKA-2134
        if (part == null) {
          continue;
        }
        for (PackageRelationship drawRel : part
            .getRelationshipsByType(XSSFRelation.SHEET_HYPERLINKS.getRelation())) {
          drawingHyperlinks.put(drawRel.getId(), drawRel.getTargetURI().toString());
        }
      }
    }
  } catch (InvalidFormatException e) {
    //swallow
    //an exception trying to extract
    //hyperlinks on drawings should not cause a parse failure
  }
}

代码示例来源:origin: apache/tika

for (PackageRelationship rel : part.getRelationshipsByType(XSSFRelation.DRAWINGS.getRelation())) {
  if (rel.getTargetMode() == TargetMode.INTERNAL) {
    PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
for (PackageRelationship rel : part.getRelationshipsByType(XSSFRelation.VML_DRAWINGS.getRelation())) {
  if (rel.getTargetMode() == TargetMode.INTERNAL) {
    PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());

代码示例来源:origin: apache/tika

XSSFRelation.CHART.getRelation(),
"chart",
parentDrawing.getPackagePart(),

代码示例来源:origin: apache/tika

XSSFRelation.CHART.getRelation(),
"chart",
document.getPackagePart(),

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

private void loadUrlsFromSheetRels(PackagePart sheetPart) {
  try {
    for (PackageRelationship rel : sheetPart.getRelationshipsByType(XSSFRelation.SHEET_HYPERLINKS.getRelation())) {
      relIdToHyperlink.put(rel.getId(), rel.getTargetURI().toString());
    }
  } catch (InvalidFormatException e) {
    //swallow
  }
}

代码示例来源:origin: apache/tika

XSSFRelation.CHART.getRelation(),
XWPFRelation.FOOTNOTE.getRelation(),
XWPFRelation.COMMENT.getRelation(),

代码示例来源:origin: org.apache.tika/tika-parsers

protected void extractHyperLinks(PackagePart sheetPart, XHTMLContentHandler xhtml) throws SAXException {
  try {
    for (PackageRelationship rel : sheetPart.getRelationshipsByType(XSSFRelation.SHEET_HYPERLINKS.getRelation())) {
      xhtml.startElement("a", "href", rel.getTargetURI().toString());
      xhtml.characters(rel.getTargetURI().toString());
      xhtml.endElement("a");
    }
  } catch (InvalidFormatException e) {
    //swallow
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi

/**
 * Generates the relation if required
 */
protected void generateRelationIfNeeded(PackagePart sheetPart) {
  if (_externalRel == null && needsRelationToo()) {
    // Generate the relation
    PackageRelationship rel =
        sheetPart.addExternalRelationship(_location, XSSFRelation.SHEET_HYPERLINKS.getRelation());
    // Update the r:id
    _ctHyperlink.setId(rel.getId());
  }
}

代码示例来源:origin: org.openl.rules/org.openl.lib.poi.dev

/**
 * 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());
  }
}

相关文章