Example usage for org.apache.poi.xssf.usermodel XSSFRelation DRAWINGS

List of usage examples for org.apache.poi.xssf.usermodel XSSFRelation DRAWINGS

Introduction

In this page you can find the example usage for org.apache.poi.xssf.usermodel XSSFRelation DRAWINGS.

Prototype

XSSFRelation DRAWINGS

To view the source code for org.apache.poi.xssf.usermodel XSSFRelation DRAWINGS.

Click Source Link

Usage

From source file:mj.ocraptor.extraction.tika.parser.microsoft.ooxml.XSSFExcelExtractorDecorator.java

License:Apache License

/**
 * In Excel files, sheets have things embedded in them, and sheet drawings
 * which have the images/* w  ww  .j ava2 s . c o  m*/
 */
@Override
protected List<PackagePart> getMainDocumentParts() throws TikaException {
    List<PackagePart> parts = new ArrayList<PackagePart>();
    for (PackagePart part : sheetParts) {
        // Add the sheet
        parts.add(part);

        // If it has drawings, return those too
        try {
            for (PackageRelationship rel : part.getRelationshipsByType(XSSFRelation.DRAWINGS.getRelation())) {
                if (rel.getTargetMode() == TargetMode.INTERNAL) {
                    PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
                    parts.add(rel.getPackage().getPart(relName));
                }
            }
            for (PackageRelationship rel : part
                    .getRelationshipsByType(XSSFRelation.VML_DRAWINGS.getRelation())) {
                if (rel.getTargetMode() == TargetMode.INTERNAL) {
                    PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
                    parts.add(rel.getPackage().getPart(relName));
                }
            }
        } catch (InvalidFormatException e) {
            throw new TikaException("Broken OOXML file", e);
        }
    }

    return parts;
}