Java Examples for org.apache.poi.POIXMLProperties

The following java examples will help you to understand the usage of org.apache.poi.POIXMLProperties. These source code samples are taken from different open source projects.

Example 1
Project: qcadoo-master  File: AbstractXLSXView.java View source code
/**
     * Renders the Excel view, given the specified model.
     */
@Override
protected final void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
    XSSFWorkbook workbook;
    ByteArrayOutputStream baos = createTemporaryOutputStream();
    workbook = new XSSFWorkbook();
    POIXMLProperties xmlProps = workbook.getProperties();
    POIXMLProperties.CoreProperties coreProps = xmlProps.getCoreProperties();
    coreProps.setCreator(CREATOR);
    buildExcelDocument(model, workbook, request, response);
    workbook.write(baos);
    writeToResponse(response, baos);
}
Example 2
Project: poi-master  File: TestXSSFBugs.java View source code
@Test
public void bug54764() throws IOException, OpenXML4JException, XmlException {
    OPCPackage pkg = XSSFTestDataSamples.openSamplePackage("54764.xlsx");
    // Check the core properties - will be found but empty, due
    //  to the expansion being too much to be considered valid
    POIXMLProperties props = new POIXMLProperties(pkg);
    assertEquals(null, props.getCoreProperties().getTitle());
    assertEquals(null, props.getCoreProperties().getSubject());
    assertEquals(null, props.getCoreProperties().getDescription());
    // Now check the spreadsheet itself
    try {
        new XSSFWorkbook(pkg).close();
        fail("Should fail as too much expansion occurs");
    } catch (POIXMLException e) {
    }
    pkg.close();
    // Try with one with the entities in the Content Types
    try {
        XSSFTestDataSamples.openSamplePackage("54764-2.xlsx").close();
        fail("Should fail as too much expansion occurs");
    } catch (Exception e) {
    }
    // Check we can still parse valid files after all that
    Workbook wb = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx");
    assertEquals(3, wb.getNumberOfSheets());
    wb.close();
}
Example 3
Project: constellio-master  File: OfficeDocumentsServices.java View source code
public void setPropertyNewDocument(String ext, StreamFactory<InputStream> inputStreamFactory, StreamFactory<OutputStream> outputStreamFactory, String propertyName, String propertyValue) throws IOException, PropertyDoesntExist, NotCompatibleExtension, CannotReadDocumentsProperties {
    POIXMLDocument doc = parseDocument(ext, inputStreamFactory, propertyName);
    org.apache.poi.POIXMLProperties.CustomProperties customProperties = doc.getProperties().getCustomProperties();
    int index = 0;
    for (CTProperty prop : customProperties.getUnderlyingProperties().getPropertyList()) {
        if (prop.getName().equals(propertyName)) {
            customProperties.getUnderlyingProperties().removeProperty(index);
        }
        index++;
    }
    customProperties.addProperty(propertyName, propertyValue);
    doc.write(outputStreamFactory.create(getClass().getName() + ".setPropertyNewDocument"));
}
Example 4
Project: railo-master  File: Excel.java View source code
public Struct getSummaryInfo() {
    Struct infostruct = new StructImpl();
    int sheets = workbook.getNumberOfSheets();
    infostruct.setEL("SHEETS", new Double(sheets));
    if (sheets > 0) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < sheets; i++) {
            if (i > 0)
                sb.append(',');
            sb.append(workbook.getSheetName(i));
        }
        infostruct.setEL("SHEETNAMES", sb.toString());
    }
    if (xmlFormat == FORMAT_HSSF) {
        infostruct.setEL("SPREADSHEETTYPE", "Excel");
        HSSFWorkbook hssfworkbook = (HSSFWorkbook) workbook;
        info(infostruct, hssfworkbook.getSummaryInformation());
        info(infostruct, hssfworkbook.getDocumentSummaryInformation());
    } else if (xmlFormat == FORMAT_XSSF) {
        infostruct.put("SPREADSHEETTYPE", "Excel (2007)");
        XSSFWorkbook xssfworkbook = (XSSFWorkbook) workbook;
        POIXMLProperties props = xssfworkbook.getProperties();
        info(infostruct, props.getCoreProperties().getUnderlyingProperties());
        info(infostruct, props.getExtendedProperties().getUnderlyingProperties());
    }
    return infostruct;
}
Example 5
Project: ktdocumentindexer-master  File: KTMetaData.java View source code
public java.util.Map<String, String> readOOXMLProperty(String fileName, int type, String keyName) {
    this.logger.debug("POI Properties - OOXML: Read metadata from file " + fileName);
    // Initialise result
    java.util.Hashtable result = new java.util.Hashtable();
    java.util.Hashtable metadata = new java.util.Hashtable();
    // Open the document
    POIXMLDocument poi_doc;
    try {
        this.logger.debug("POI Properties - OOXML: Open document stream");
        // Use the extension to determine and initialise the correct document type
        switch(type) {
            case 1:
                this.logger.debug("POI Properties - OOXML: File is of type docx");
                FileInputStream inStream = new FileInputStream(fileName);
                poi_doc = new XWPFDocument(inStream);
                inStream.close();
                break;
            case 2:
                this.logger.debug("POI Properties - OOXML: File is of type xlsx");
                poi_doc = new XSSFWorkbook(fileName);
                break;
            case 3:
                this.logger.debug("POI Properties - OOXML: File is of type pptx");
                poi_doc = new XSLFSlideShow(fileName);
                break;
            default:
                this.logger.error("POI Properties - OOXML: Input file should be of type docx, xlsx or pptx.");
                result.put("status", "1");
                result.put("metadata", metadata);
                return result;
        }
    } catch (Exception ex) {
        this.logger.error("POI Properties - OOXML: Input file could not be opened: " + ex.getMessage());
        ex.printStackTrace();
        result.put("status", "1");
        result.put("metadata", metadata);
        return result;
    }
    // Read in the properties
    POIXMLProperties.CustomProperties customProps;
    try {
        this.logger.debug("POI Properties - OOXML: Read custom properties");
        customProps = poi_doc.getProperties().getCustomProperties();
        if (customProps == null) {
            this.logger.debug("POI Properties - OOXML: No custom properties have been defined.");
            result.put("status", "0");
            result.put("metadata", metadata);
            return result;
        }
        org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperties ctProps = poi_doc.getProperties().getCustomProperties().getUnderlyingProperties();
        org.openxmlformats.schemas.officeDocument.x2006.customProperties.CTProperty p;
        int size = ctProps.sizeOfPropertyArray();
        int count = 0;
        while (size != count) {
            p = ctProps.getPropertyArray(count);
            String key = p.getName();
            if (key.equals(keyName)) {
                String value = p.getLpwstr();
                metadata.put(key, value);
                this.logger.debug("POI Properties - OOXML: Custom property - name " + key + "; value " + value);
            }
            count++;
        }
    } catch (Exception ex) {
        this.logger.error("POI Properties - OOXML: Custom properties could not be found: " + ex.getMessage());
        ex.printStackTrace();
        result.put("status", "1");
        result.put("metadata", metadata);
        return result;
    }
    result.put("status", "0");
    result.put("metadata", metadata);
    return result;
}
Example 6
Project: com.opendoorlogistics-master  File: PoiIO.java View source code
public static boolean exportDatastore(ODLDatastore<? extends ODLTableReadOnly> ds, File file, boolean xlsx, ProcessingApi processing, ExecutionReport report) {
    //tmpFileBugFix();
    Workbook wb = null;
    SXSSFWorkbook sxssfwb = null;
    HSSFWorkbook hssfwb = null;
    if (xlsx == false) {
        hssfwb = new HSSFWorkbook();
        hssfwb.createInformationProperties();
        hssfwb.getSummaryInformation().setAuthor(AppConstants.ORG_NAME);
        wb = hssfwb;
    } else {
        //	sxssfwb = new SXSSFWorkbook(100); // keep 100 rows in memory, exceeding rows will be flushed to disk
        sxssfwb = new SXSSFWorkbook(null, 100, false, true);
        wb = sxssfwb;
    //	XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
    ///	POIXMLProperties xmlProps = sxssfwb.
    //POIXMLProperties.CoreProperties coreProps = xmlProps.getCoreProperties();
    //	coreProps.setCreator(AppConstants.ORG_NAME);
    //	wb = xssfWorkbook;
    }
    try {
        // save schema
        addSchema(ds, wb);
        for (ODLTableDefinition table : TableUtils.getAlphabeticallySortedTables(ds)) {
            ODLTableReadOnly tro = (ODLTableReadOnly) table;
            Sheet sheet = wb.createSheet(tro.getName());
            if (sheet == null) {
                return false;
            }
            exportTable(sheet, tro, 0, processing, report);
            if (processing != null && processing.isCancelled()) {
                return false;
            }
        }
        if (processing != null) {
            processing.postStatusMessage("Saving whole workbook to disk.");
        }
        saveWorkbook(file, wb);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (sxssfwb != null) {
            sxssfwb.dispose();
        }
        if (hssfwb != null) {
            try {
                hssfwb.close();
            } catch (Exception e2) {
            }
        }
    }
    return true;
}
Example 7
Project: OOXML-master  File: XSSFWorkbook.java View source code
/**
     * Create a new CTWorkbook with all values set to default
     */
private void onWorkbookCreate() {
    workbook = CTWorkbook.Factory.newInstance();
    // don't EVER use the 1904 date system
    CTWorkbookPr workbookPr = workbook.addNewWorkbookPr();
    workbookPr.setDate1904(false);
    CTBookViews bvs = workbook.addNewBookViews();
    CTBookView bv = bvs.addNewWorkbookView();
    bv.setActiveTab(0);
    workbook.addNewSheets();
    POIXMLProperties.ExtendedProperties expProps = getProperties().getExtendedProperties();
    expProps.getUnderlyingProperties().setApplication(DOCUMENT_CREATOR);
    sharedStringSource = (SharedStringsTable) createRelationship(XSSFRelation.SHARED_STRINGS, XSSFFactory.getInstance());
    stylesSource = (StylesTable) createRelationship(XSSFRelation.STYLES, XSSFFactory.getInstance());
    namedRanges = new ArrayList<XSSFName>();
    sheets = new ArrayList<XSSFSheet>();
}
Example 8
Project: nextreports-engine-master  File: XlsxExporter.java View source code
private void createSummaryInformation(String title) {
    DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
    POIXMLProperties xmlProps = wb.getProperties();
    POIXMLProperties.CoreProperties coreProps = xmlProps.getCoreProperties();
    coreProps.setTitle(title);
    coreProps.setCreator(ReleaseInfoAdapter.getCompany());
    coreProps.setDescription("NextReports " + ReleaseInfoAdapter.getVersionNumber());
    xmlProps.getExtendedProperties().getUnderlyingProperties().setApplication("NextReports " + ReleaseInfoAdapter.getVersionNumber());
    coreProps.setSubjectProperty("Created by NextReports Designer" + ReleaseInfoAdapter.getVersionNumber());
    coreProps.setCreated(df.format(new Date()));
    coreProps.setKeywords(ReleaseInfoAdapter.getHome());
}
Example 9
Project: tika-master  File: XSLFEventBasedPowerPointExtractor.java View source code
public POIXMLProperties.CoreProperties getCoreProperties() {
    return this.properties.getCoreProperties();
}