Example usage for org.apache.poi.ss.usermodel PictureData getMimeType

List of usage examples for org.apache.poi.ss.usermodel PictureData getMimeType

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel PictureData getMimeType.

Prototype

String getMimeType();

Source Link

Document

Returns the mime type for the image

Usage

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   www .  j av  a2 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);
    }
}