Example usage for org.apache.poi.xssf.usermodel XSSFWorkbook getAllEmbedds

List of usage examples for org.apache.poi.xssf.usermodel XSSFWorkbook getAllEmbedds

Introduction

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

Prototype

@Deprecated
@Removal(version = "4.2")
public List<PackagePart> getAllEmbedds() throws OpenXML4JException 

Source Link

Document

Get the document's embedded files.

Usage

From source file:poi.xssf.usermodel.examples.EmbeddedObjects.java

License:Apache License

public static void main(String[] args) throws Exception {
    OPCPackage pkg = OPCPackage.open(args[0]);
    XSSFWorkbook workbook = new XSSFWorkbook(pkg);
    for (PackagePart pPart : workbook.getAllEmbedds()) {
        String contentType = pPart.getContentType();
        // Excel Workbook - either binary or OpenXML
        if (contentType.equals("application/vnd.ms-excel")) {
            HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(pPart.getInputStream());
        }/*from  w  w  w.j  av a  2 s. c o m*/
        // Excel Workbook - OpenXML file format
        else if (contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {
            XSSFWorkbook embeddedWorkbook = new XSSFWorkbook(pPart.getInputStream());
        }
        // Word Document - binary (OLE2CDF) file format
        else if (contentType.equals("application/msword")) {
            HWPFDocument document = new HWPFDocument(pPart.getInputStream());
        }
        // Word Document - OpenXML file format
        else if (contentType
                .equals("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) {
            XWPFDocument document = new XWPFDocument(pPart.getInputStream());
        }
        // PowerPoint Document - binary file format
        else if (contentType.equals("application/vnd.ms-powerpoint")) {
            HSLFSlideShow slideShow = new HSLFSlideShow(pPart.getInputStream());
        }
        // PowerPoint Document - OpenXML file format
        else if (contentType
                .equals("application/vnd.openxmlformats-officedocument.presentationml.presentation")) {
            OPCPackage docPackage = OPCPackage.open(pPart.getInputStream());
            XSLFSlideShow slideShow = new XSLFSlideShow(docPackage);
        }
        // Any other type of embedded object.
        else {
            System.out.println("Unknown Embedded Document: " + contentType);
            InputStream inputStream = pPart.getInputStream();
        }
    }
    pkg.close();
}