Example usage for org.apache.poi.hssf.usermodel HSSFObjectData getOLE2ClassName

List of usage examples for org.apache.poi.hssf.usermodel HSSFObjectData getOLE2ClassName

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFObjectData getOLE2ClassName.

Prototype

@Override
    public String getOLE2ClassName() 

Source Link

Usage

From source file:poi.hssf.usermodel.examples.EmeddedObjects.java

License:Apache License

public static void main(String[] args) throws Exception {
    POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(args[0]));
    HSSFWorkbook workbook = new HSSFWorkbook(fs);
    for (HSSFObjectData obj : workbook.getAllEmbeddedObjects()) {
        //the OLE2 Class Name of the object
        String oleName = obj.getOLE2ClassName();
        if (oleName.equals("Worksheet")) {
            DirectoryNode dn = (DirectoryNode) obj.getDirectory();
            HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(dn, fs, false);
            //System.out.println(entry.getName() + ": " + embeddedWorkbook.getNumberOfSheets());
        } else if (oleName.equals("Document")) {
            DirectoryNode dn = (DirectoryNode) obj.getDirectory();
            HWPFDocument embeddedWordDocument = new HWPFDocument(dn);
            //System.out.println(entry.getName() + ": " + embeddedWordDocument.getRange().text());
        } else if (oleName.equals("Presentation")) {
            DirectoryNode dn = (DirectoryNode) obj.getDirectory();
            SlideShow embeddedPowerPointDocument = new SlideShow(new HSLFSlideShow(dn));
            //System.out.println(entry.getName() + ": " + embeddedPowerPointDocument.getSlides().length);
        } else {//from www.  j  a v a  2 s. c om
            if (obj.hasDirectoryEntry()) {
                // The DirectoryEntry is a DocumentNode. Examine its entries to find out what it is
                DirectoryNode dn = (DirectoryNode) obj.getDirectory();
                for (Iterator entries = dn.getEntries(); entries.hasNext();) {
                    Entry entry = (Entry) entries.next();
                    //System.out.println(oleName + "." + entry.getName());
                }
            } else {
                // There is no DirectoryEntry
                // Recover the object's data from the HSSFObjectData instance.
                byte[] objectData = obj.getObjectData();
            }
        }
    }
}

From source file:uk.ac.liverpool.spreadsheet.ExcelFeatureAnalysis.java

License:Apache License

private static void analyseSpreadsheet(Element da, ExcelFeatureAnalysis efa) {

    Element s = new Element("spreadsheets", sn);
    da.addContent(s);//from   w  ww.ja  v a 2  s.  c o m
    s.setAttribute("numberOfSheets", "" + efa.wb.getNumberOfSheets());
    // workbook wide features

    List<? extends PictureData> allPictures = efa.wb.getAllPictures();
    if (allPictures != null && allPictures.size() > 0) {
        Element oo = new Element("Pictures", sn);
        s.addContent(oo);
        for (PictureData pd : allPictures) {
            Element ob = new Element("Picture", sn);
            ob.setAttribute("mimeType", pd.getMimeType());
            oo.addContent(ob);
        }
    }

    int numfonts = efa.wb.getNumberOfFonts();
    if (numfonts > 0) {
        Element oo = new Element("Fonts", sn);
        s.addContent(oo);
        for (int i = 0; i < numfonts; i++) {
            Font cs = efa.wb.getFontAt((short) i);
            Element ob = new Element("Font", sn);
            ob.setAttribute("Name", cs.getFontName());

            ob.setAttribute("Charset", "" + cs.getCharSet());
            oo.addContent(ob);
        }
    }

    if (efa.hswb != null) {

        DocumentSummaryInformation dsi = efa.hswb.getDocumentSummaryInformation();
        if (dsi != null)
            s.setAttribute("OSVersion", "" + dsi.getOSVersion());
        // Property[] properties = dsi.getProperties();
        // CustomProperties customProperties = dsi.getCustomProperties();

        List<HSSFObjectData> eo = efa.hswb.getAllEmbeddedObjects();
        if (eo != null && eo.size() > 0) {
            Element oo = new Element("EmbeddedObjects", sn);
            s.addContent(oo);
            for (HSSFObjectData o : eo) {
                Element ob = new Element("EmbeddedObject", sn);
                ob.setAttribute("name", o.getOLE2ClassName());
                oo.addContent(ob);
            }

        }
    } else if (efa.xswb != null) {
        try {
            POIXMLProperties properties = efa.xswb.getProperties();
            List<PackagePart> allEmbedds = efa.xswb.getAllEmbedds();
            if (allEmbedds != null && allEmbedds.size() > 0) {
                Element oo = new Element("EmbeddedObjects", sn);
                s.addContent(oo);

                for (PackagePart p : allEmbedds) {
                    Element ob = new Element("EmbeddedObject", sn);
                    ob.setAttribute("mimeType", p.getContentType());
                    ob.setAttribute("name", p.getPartName().getName());

                    oo.addContent(ob);
                }
            }
        } catch (OpenXML4JException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
    int nn = efa.wb.getNumberOfNames();
    if (nn > 0) {
        Element oo = new Element("NamedCells", sn);
        s.addContent(oo);
    }

    // sheet specific features
    int total = efa.wb.getNumberOfSheets();
    for (int c = 0; c < total; c++) {
        Sheet sheet = efa.wb.getSheetAt(c);
        Element single = new Element("sheet", sn);
        s.addContent(single);
        analyseSheet(sheet, single, sn, efa);
    }
}