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

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

Introduction

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

Prototype

public POIXMLProperties getProperties() 

Source Link

Document

Get the document properties.

Usage

From source file:com.opendoorlogistics.core.tables.io.PoiIO.java

License:Open Source License

private static String getAuthor(Workbook wb) {
    if (HSSFWorkbook.class.isInstance(wb)) {
        HSSFWorkbook hssf = (HSSFWorkbook) wb;
        SummaryInformation info = hssf.getSummaryInformation();
        if (info != null) {
            return info.getAuthor();
        }/* w  w w. j  a  v  a  2  s .  c o m*/
    } else if (XSSFWorkbook.class.isInstance(wb)) {
        XSSFWorkbook xssf = (XSSFWorkbook) wb;
        POIXMLProperties xmlProps = xssf.getProperties();
        if (xmlProps != null) {
            POIXMLProperties.CoreProperties coreProps = xmlProps.getCoreProperties();
            if (coreProps != null) {
                return coreProps.getCreator();
            }
        }
    }
    return null;
}

From source file:com.xhsoft.framework.common.file.ExcelHandle.java

License:Open Source License

public void setDocInfo(XSSFWorkbook xlsx) {
    POIXMLProperties.CoreProperties props = xlsx.getProperties().getCoreProperties();

    //props.setTitle(title);
    //props.setSubjectProperty(subject);
    //props.setCategory(category);
    //props.setDescription(desc);

    //props.setCreator(author);

}

From source file:de.bund.bfr.knime.openkrise.db.imports.custom.bfrnewformat.TraceGenerator.java

License:Open Source License

private boolean save(XSSFWorkbook workbook, String filename) {
    try {//from www.j a  v  a  2  s. c om
        File f = new File(filename);
        if (f.exists()) {
            int returnVal = JOptionPane.showConfirmDialog(parent, "Replace file '" + filename + "'?",
                    "Excel file '" + filename + "' exists already", JOptionPane.YES_NO_OPTION);
            if (returnVal == JOptionPane.NO_OPTION)
                return false;
            else if (returnVal == JOptionPane.YES_OPTION)
                ;
            else
                return false;
        }
        POIXMLProperties.CoreProperties coreProp = workbook.getProperties().getCoreProperties();
        coreProp.setCreator("FoodChain-Lab");
        coreProp.setCreated(new Nullable<Date>(new Date(System.currentTimeMillis())));
        // Write the workbook in file system
        FileOutputStream out = new FileOutputStream(f);
        workbook.write(out);
        out.close();
        System.out.println(filename + " written successfully on disk.");
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:edu.casetools.rcase.extensions.excel.control.Exporter.java

License:Open Source License

private void setExcel2007Properties(String templateName) {
    XSSFWorkbook xworkbook = (XSSFWorkbook) this.workbook;
    POIXMLProperties properties = xworkbook.getProperties();
    properties.getCoreProperties().setCreator(I18nMessageService.getString("Excel.Author"));

    CTProperties ext = properties.getExtendedProperties().getUnderlyingProperties();
    ext.setCompany(I18nMessageService.getString("Excel.Company"));
    ext.setApplication(I18nMessageService.getString("Excel.Application"));

    POIXMLProperties.CustomProperties customProperties = properties.getCustomProperties();
    customProperties.addProperty("Table Template", templateName);
}

From source file:lucee.runtime.poi.Excel.java

License:Open Source License

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));
        }/*  w  ww  .  j ava2s . c  o  m*/
        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;
}

From source file:org.alanwilliamson.openbd.plugin.spreadsheet.functions.SpreadsheetAddInfo.java

License:Open Source License

public cfData execute(cfSession _session, List<cfData> parameters) throws cfmRunTimeException {
    if (parameters.get(0).getDataType() != cfData.CFSTRUCTDATA)
        throwException(_session, "parameter must be of type structure");

    cfSpreadSheetData spreadsheet = (cfSpreadSheetData) parameters.get(1);
    cfStructData s = (cfStructData) parameters.get(0);

    Workbook workbook = spreadsheet.getWorkBook();

    /*/*from  w  w w  . j av a2 s  . c om*/
     * XSSFWorkbook
     */
    if (workbook instanceof XSSFWorkbook) {
        XSSFWorkbook xSSFWorkbook = (XSSFWorkbook) workbook;

        CoreProperties cP = xSSFWorkbook.getProperties().getCoreProperties();

        if (s.containsKey("author"))
            cP.setCreator(s.getData("author").getString());
        if (s.containsKey("category"))
            cP.setCategory(s.getData("category").getString());
        if (s.containsKey("subject"))
            cP.setSubjectProperty(s.getData("subject").getString());
        if (s.containsKey("title"))
            cP.setTitle(s.getData("title").getString());
        if (s.containsKey("revision"))
            cP.setRevision(s.getData("revision").getString());
        if (s.containsKey("description"))
            cP.setDescription(s.getData("description").getString());

    } else {
        HSSFWorkbook hSSFWorkbook = (HSSFWorkbook) workbook;
        DocumentSummaryInformation dSummary = hSSFWorkbook.getDocumentSummaryInformation();

        if (dSummary == null) {
            hSSFWorkbook.createInformationProperties();
            dSummary = hSSFWorkbook.getDocumentSummaryInformation();
        }

        if (s.containsKey("category"))
            dSummary.setCategory(s.getData("category").getString());
        if (s.containsKey("manager"))
            dSummary.setManager(s.getData("manager").getString());
        if (s.containsKey("company"))
            dSummary.setCompany(s.getData("company").getString());

        SummaryInformation sInformation = hSSFWorkbook.getSummaryInformation();

        if (s.containsKey("title"))
            sInformation.setTitle(s.getData("title").getString());
        if (s.containsKey("subject"))
            sInformation.setSubject(s.getData("subject").getString());
        if (s.containsKey("author"))
            sInformation.setAuthor(s.getData("author").getString());
        if (s.containsKey("comments"))
            sInformation.setComments(s.getData("comments").getString());
        if (s.containsKey("keywords"))
            sInformation.setKeywords(s.getData("keywords").getString());
        if (s.containsKey("lastauthor"))
            sInformation.setLastAuthor(s.getData("lastauthor").getString());
    }

    return cfBooleanData.TRUE;
}

From source file:org.alanwilliamson.openbd.plugin.spreadsheet.functions.SpreadsheetInfo.java

License:Open Source License

public cfData execute(cfSession _session, List<cfData> parameters) throws cfmRunTimeException {
    cfSpreadSheetData spreadsheet = null;
    spreadsheet = (cfSpreadSheetData) parameters.get(0);

    Workbook workbook = spreadsheet.getWorkBook();
    cfStructData s = new cfStructData();

    /*/*from   w  w  w.  j av  a  2s.  c o  m*/
     * Sheet details
     */
    s.setData("sheets", new cfNumberData(workbook.getNumberOfSheets()));
    cfArrayData sheetArr = cfArrayData.createArray(1);
    for (int x = 0; x < workbook.getNumberOfSheets(); x++) {
        String name = workbook.getSheetName(x);
        if (name == null)
            name = "";

        sheetArr.addElement(new cfStringData(name));
    }
    s.setData("sheetnames", sheetArr);

    /*
     * Workbook type
     */
    if (workbook instanceof XSSFWorkbook) {
        s.setData("spreadsheettype", new cfStringData("xlsx"));
    } else {
        s.setData("spreadsheettype", new cfStringData("xls"));
    }

    /*
     * XSSFWorkbook
     */
    if (workbook instanceof XSSFWorkbook) {
        XSSFWorkbook xSSFWorkbook = (XSSFWorkbook) workbook;

        CoreProperties cP = xSSFWorkbook.getProperties().getCoreProperties();
        s.setData("category", new cfStringData(cP.getCategory()));
        s.setData("subject", new cfStringData(cP.getSubject()));
        s.setData("title", new cfStringData(cP.getTitle()));
        s.setData("revision", new cfStringData(cP.getRevision()));
        s.setData("author", new cfStringData(cP.getCreator()));
        s.setData("description", new cfStringData(cP.getDescription()));

        if (cP.getLastPrinted() != null)
            s.setData("lastprinted", new cfDateData(cP.getLastPrinted()));
        if (cP.getModified() != null)
            s.setData("lastsaved", new cfDateData(cP.getModified()));
        if (cP.getCreated() != null)
            s.setData("creationdate", new cfDateData(cP.getCreated()));

    } else {
        HSSFWorkbook hSSFWorkbook = (HSSFWorkbook) workbook;
        DocumentSummaryInformation dSummary = hSSFWorkbook.getDocumentSummaryInformation();

        if (dSummary == null) {
            s.setData("category", cfStringData.EMPTY_STRING);
            s.setData("company", cfStringData.EMPTY_STRING);
            s.setData("manager", cfStringData.EMPTY_STRING);
        } else {
            s.setData("category", new cfStringData(dSummary.getCategory()));
            s.setData("company", new cfStringData(dSummary.getCompany()));
            s.setData("manager", new cfStringData(dSummary.getManager()));
        }

        SummaryInformation sInformation = hSSFWorkbook.getSummaryInformation();
        if (sInformation == null) {

            s.setData("author", cfStringData.EMPTY_STRING);
            s.setData("comments", cfStringData.EMPTY_STRING);
            s.setData("keywords", cfStringData.EMPTY_STRING);
            s.setData("lastauthor", cfStringData.EMPTY_STRING);
            s.setData("title", cfStringData.EMPTY_STRING);
            s.setData("subject", cfStringData.EMPTY_STRING);

        } else {

            s.setData("author", new cfStringData(sInformation.getAuthor()));
            s.setData("comments", new cfStringData(sInformation.getComments()));
            s.setData("keywords", new cfStringData(sInformation.getKeywords()));
            s.setData("lastauthor", new cfStringData(sInformation.getLastAuthor()));
            s.setData("title", new cfStringData(sInformation.getTitle()));
            s.setData("subject", new cfStringData(sInformation.getSubject()));

            if (sInformation.getCreateDateTime() != null)
                s.setData("creationdate", new cfDateData(sInformation.getCreateDateTime()));

            if (sInformation.getLastSaveDateTime() != null)
                s.setData("lastsaved", new cfDateData(sInformation.getLastSaveDateTime()));

            if (sInformation.getLastPrinted() != null)
                s.setData("lastprinted", new cfDateData(sInformation.getLastPrinted()));

        }

    }

    return s;
}

From source file:org.alfresco.bm.api.v1.RestAPITest.java

License:Open Source License

/**
 * Checks the test application APIs for retrieving test results.
 *///  w  w  w  .java  2  s  .c o  m
@Test
public synchronized void testScenario07() throws Exception {
    /*
     * In-memory byte[] are used because we know the size of the documents
     * will be manageable.
     */

    executeTestRun("T07", "A test for scenario 07.", "01", "Scenario 07 - Run 01");

    // Get report for test run that does not exist
    try {
        ResultsRestAPI resultsAPI = api.getTestRunResultsAPI("T07MISSING", "01");
        resultsAPI.getReportCSV();
        Assert.fail("Expected exception regarding missing test.");
    } catch (WebApplicationException e) {
        assertEquals(Status.NOT_FOUND.getStatusCode(), e.getResponse().getStatus());
    }

    ResultsRestAPI resultsAPI = api.getTestRunResultsAPI("T07", "01");

    // Get the results CSV
    StreamingOutput csvOutput = resultsAPI.getReportCSV();
    ByteArrayOutputStream csvBos = new ByteArrayOutputStream();
    csvBos.close();
    csvOutput.write(csvBos);
    String csvResults = new String(csvBos.toByteArray());
    // Check
    assertTrue(csvResults.contains("Data:,bm21-data.T07.01.results"));
    assertTrue(csvResults.contains("Started"));
    assertTrue(csvResults.contains("Finished"));
    assertTrue(csvResults.contains("Duration"));

    // Get the JSON results
    String chartJson = resultsAPI.getTimeSeriesResults(0L, "seconds", 1, 5, false);
    assertTrue(chartJson.startsWith("[ { \"time\" : "));
    assertTrue(chartJson.contains("[ { \"time\" : "));
    assertTrue(chartJson.contains("000 , \"name\" : \"start\" , \"mean\" : "));
    assertTrue(chartJson.endsWith(" , \"fail\" : 0 , \"failPerSec\" : 0.0}]"));

    // Get the XLSX report
    StreamingOutput xlsxOutput = resultsAPI.getReportXLSX();
    ByteArrayOutputStream xlsxBos = new ByteArrayOutputStream();
    xlsxOutput.write(xlsxBos);
    xlsxBos.close();
    ByteArrayInputStream xlsxBis = new ByteArrayInputStream(xlsxBos.toByteArray());
    XSSFWorkbook xlsxWorkbook = new XSSFWorkbook(xlsxBis);
    xlsxBis.close();
    // Write it to a temp file just for fun
    File xlsxFile = File.createTempFile(UUID.randomUUID().toString(), ".xlsx");
    FileOutputStream xlsxFos = new FileOutputStream(xlsxFile);
    xlsxWorkbook.write(xlsxFos);
    xlsxFos.close();
    logger.info("XLSX report found here: " + xlsxFile);

    // Check
    POIXMLProperties xlsxProperties = xlsxWorkbook.getProperties();
    CoreProperties xlsxCoreProperties = xlsxProperties.getCoreProperties();
    Assert.assertNotNull("No XLSX description: " + xlsxFile, xlsxCoreProperties.getDescription());
    Assert.assertTrue("Title in XLSX must contain test run FQN: " + xlsxFile,
            xlsxCoreProperties.getTitle().contains("T07.01"));
    Assert.assertTrue("Description in XLSX must contain test name and description: " + xlsxFile,
            xlsxCoreProperties.getDescription().contains("A test for scenario 07."));
    Assert.assertTrue("Description in XLSX must contain test name and description." + xlsxFile,
            xlsxCoreProperties.getDescription().contains("Scenario 07 - Run 01"));
    xlsxWorkbook.close();
}

From source file:org.alfresco.bm.report.XLSXReporter.java

License:Open Source License

private void writeMetadata(XSSFWorkbook workbook) throws IOException, NotFoundException {
    TestService testService = getTestService();

    CoreProperties workbookCoreProperties = workbook.getProperties().getCoreProperties();

    // Title/*from   www. j  a  va  2s  .c o  m*/
    workbookCoreProperties.setTitle(title);

    // Description
    StringBuilder description = new StringBuilder(128);
    DBObject testObj = testService.getTestMetadata(test);
    String testDescription = (String) testObj.get(FIELD_DESCRIPTION);
    if (testDescription != null) {
        description.append(testDescription).append("\n");
    }
    DBObject testRunObj = testService.getTestRunMetadata(test, run);
    String testRunDescription = (String) testRunObj.get(FIELD_DESCRIPTION);
    if (testRunDescription != null) {
        description.append(testRunDescription);
    }
    workbookCoreProperties.setDescription(description.toString().trim());

    // Created
    Long time = (Long) testRunObj.get(FIELD_STARTED);
    if (time > 0) {
        workbookCoreProperties.setCreated(new Nullable<Date>(new Date(time)));
    }
}

From source file:org.keyboardplaying.xtt.xlsx.XlsxNormalizer.java

License:Apache License

/**
 * Normalizes the time tracker workbook's properties to avoid unrequired changes in the SCM repository.
 * <p/>//w ww  . jav a  2  s .com
 * This sets the author, company and title with the properties of the instance, and resets the last modification
 * date with the creation date.
 *
 * @param workbook
 *            the workbook to normalize
 */
public void normalizeProperties(XSSFWorkbook workbook) {
    POIXMLProperties properties = workbook.getProperties();
    CoreProperties coreProperties = properties.getCoreProperties();

    // Set author
    coreProperties.setCreator(author);
    coreProperties.getUnderlyingProperties().setLastModifiedByProperty(author);
    properties.getExtendedProperties().getUnderlyingProperties().setCompany(company);

    // Set title
    coreProperties.setTitle(title);

    // Don't save last modification date
    coreProperties.setModified(new Nullable<>(coreProperties.getCreated()));
}