Example usage for org.apache.poi.hpsf SummaryInformation setAuthor

List of usage examples for org.apache.poi.hpsf SummaryInformation setAuthor

Introduction

In this page you can find the example usage for org.apache.poi.hpsf SummaryInformation setAuthor.

Prototype

public void setAuthor(final String author) 

Source Link

Document

Sets the author.

Usage

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

License:Open Source License

private void setDefaultProperties(String templateName) {
    HSSFWorkbook hworkbook = (HSSFWorkbook) this.workbook;
    hworkbook.createInformationProperties();
    SummaryInformation si = hworkbook.getSummaryInformation();
    DocumentSummaryInformation dsi = hworkbook.getDocumentSummaryInformation();
    si.setAuthor(I18nMessageService.getString("Excel.Author"));

    dsi.setCompany(I18nMessageService.getString("Excel.Company"));
    si.setApplicationName(I18nMessageService.getString("Excel.Application"));
    org.apache.poi.hpsf.CustomProperties cp = dsi.getCustomProperties();

    cp.put("Table Template", templateName);
    dsi.setCustomProperties(cp);//from  w ww  .j  a  v  a  2 s . co  m
}

From source file:gov.nih.nci.evs.app.neopl.XLSMetadataUtils.java

License:Open Source License

public static void setAuthor(String filename, String author) {
    HSSFWorkbook workbook = null;/*www  .jav a  2s .  com*/
    FileInputStream fis = null;
    try {
        System.out.println(filename);
        fis = new FileInputStream(filename);
        workbook = new HSSFWorkbook(fis);
        workbook.createInformationProperties();
        SummaryInformation summaryInfo = workbook.getSummaryInformation();
        summaryInfo.setAuthor(author);

    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        try {
            fis.close();
        } catch (Exception ex) {

        }
    }
    FileOutputStream fos = null;

    try {
        fos = new FileOutputStream(new File(filename));
        workbook.write(fos);
        fos.flush();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        try {
            fos.close();
            System.out.println("Outputfile " + filename + " generated.");
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

From source file:gov.nih.nci.evs.app.neopl.XLSXMetadataUtils.java

License:Open Source License

public static void setSummaryData(String filename, String[] keys, String[] values) {
    String size = getFileSize(filename);
    FileInputStream stream = null;
    try {// w  w w  .  java2  s.  c  o  m
        stream = new FileInputStream(new File(filename));
        POIFSFileSystem poifs = null;
        boolean passed = false;
        try {
            poifs = new POIFSFileSystem(stream);
            passed = true;
        } catch (Exception e) {
            passed = false;
        }
        if (!passed) {
            setPOISummaryData(filename, keys, values);
            stream.close();
            return;
        }

        HSSFWorkbook workbook = null;
        SummaryInformation summaryInfo = null;
        FileInputStream fis = null;
        try {
            System.out.println(filename);
            fis = new FileInputStream(filename);

            workbook = new HSSFWorkbook(fis);
            summaryInfo = workbook.getSummaryInformation();
            if (summaryInfo == null) {
                workbook.createInformationProperties();
                summaryInfo = workbook.getSummaryInformation();

                for (int i = 0; i < keys.length; i++) {
                    String key = keys[i];
                    String value = values[i];

                    System.out.println(key + " -> " + value);

                    if (key.compareTo(SUMMARY_DATA_AUTHOR) == 0) {
                        summaryInfo.setAuthor(value);
                    } else if (key.compareTo(SUMMARY_DATA_KEYWORDS) == 0) {
                        summaryInfo.setKeywords(value);
                    } else if (key.compareTo(SUMMARY_DATA_TITLE) == 0) {
                        summaryInfo.setTitle(value);
                    } else if (key.compareTo(SUMMARY_DATA_SUBJECT) == 0) {
                        summaryInfo.setSubject(value);
                    }
                }

            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            try {
                fis.close();
            } catch (Exception ex) {

            }
        }
        FileOutputStream fos = null;

        try {
            fos = new FileOutputStream(new File(filename));
            workbook.write(fos);
            fos.flush();
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            fos.close();
        }

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:gov.nih.nci.evs.app.neopl.XLSXMetadataUtils.java

License:Open Source License

public static void setAuthor(String filename, String author) {
    try {//from   w  w w . jav  a 2  s. c  om
        FileInputStream stream = new FileInputStream(new File(filename));
        POIFSFileSystem poifs = new POIFSFileSystem(stream);
        DirectoryEntry dir = poifs.getRoot();

        System.out.println("SummaryInformation.DEFAULT_STREAM_NAME: " + SummaryInformation.DEFAULT_STREAM_NAME);

        DocumentEntry siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
        DocumentInputStream dis = new DocumentInputStream(siEntry);
        PropertySet ps = new PropertySet(dis);
        SummaryInformation si = new SummaryInformation(ps);

        System.out.println("SummaryInformation setAuthor: " + author);

        si.setAuthor(author);

        OutputStream outStream = null;
        outStream = new FileOutputStream(new File(filename));
        byte[] buffer = new byte[1024];
        int length;

        while ((length = stream.read(buffer)) > 0) {
            outStream.write(buffer, 0, length);
        }
        outStream.close();
        stream.close();

    } catch (Exception ex) {
        ex.getStackTrace();
    }
}

From source file:gov.nih.nci.evs.app.neopl.XLSXMetadataUtils.java

License:Open Source License

public static void setAuthor(File file, String author) {
    try {//from w w  w. j ava  2  s. c o  m
        FileInputStream stream = new FileInputStream(file);
        POIFSFileSystem poifs = null;
        try {
            poifs = new POIFSFileSystem(stream);
        } catch (Exception e) {
            stream.close();
            setCreator(file, author);
            return;
        }
        DirectoryEntry dir = poifs.getRoot();
        DocumentEntry siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
        if (siEntry != null) {
            DocumentInputStream dis = new DocumentInputStream(siEntry);
            PropertySet ps = new PropertySet(dis);
            SummaryInformation si = new SummaryInformation(ps);
            si.setAuthor(author);
        }
        stream.close();
    } catch (Exception ex) {
        ex.getStackTrace();
    }
}

From source file:mat.server.service.impl.XLSGenerator.java

/** Creates the meta data.
 * // ww  w. j ava 2s  .com
 * @param wkbk - HSSFWorkbook.
 * 
 *        * */
public final void createMetaData(final HSSFWorkbook wkbk) {
    // Author: eMeasureTool, Title: Value Set Export, Subject: Value Set
    // Export, Keywords: Value Set, OID, Export, Measure, Code, Descriptor
    wkbk.createInformationProperties();
    SummaryInformation si = wkbk.getSummaryInformation();
    si.setAuthor(AUTHOR);
    si.setTitle(TITLE);
    si.setSubject(SUBJECT);
    si.setKeywords(KEYWORDS);
}

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();

    /*//  www . j  a  va 2 s .  c o  m
     * 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:poi.hpsf.examples.ModifyDocumentSummaryInformation.java

License:Apache License

/**
 * <p>Main method - see class description.</p>
 *
 * @param args The command-line parameters.
 * @throws java.io.IOException//from www  .  j  a  va 2  s. c om
 * @throws MarkUnsupportedException
 * @throws NoPropertySetStreamException
 * @throws UnexpectedPropertySetTypeException
 * @throws WritingNotSupportedException
 */
public static void main(final String[] args) throws IOException, NoPropertySetStreamException,
        MarkUnsupportedException, UnexpectedPropertySetTypeException, WritingNotSupportedException {
    /* Read the name of the POI filesystem to modify from the command line.
     * For brevity to boundary check is performed on the command-line
     * arguments. */
    File poiFilesystem = new File(args[0]);

    /* Open the POI filesystem. */
    InputStream is = new FileInputStream(poiFilesystem);
    POIFSFileSystem poifs = new POIFSFileSystem(is);
    is.close();

    /* Read the summary information. */
    DirectoryEntry dir = poifs.getRoot();
    SummaryInformation si;
    try {
        DocumentEntry siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME);
        DocumentInputStream dis = new DocumentInputStream(siEntry);
        PropertySet ps = new PropertySet(dis);
        dis.close();
        si = new SummaryInformation(ps);
    } catch (FileNotFoundException ex) {
        /* There is no summary information yet. We have to create a new
         * one. */
        si = PropertySetFactory.newSummaryInformation();
    }

    /* Change the author to "Rainer Klute". Any former author value will
     * be lost. If there has been no author yet, it will be created. */
    si.setAuthor("Rainer Klute");
    System.out.println("Author changed to " + si.getAuthor() + ".");

    /* Handling the document summary information is analogous to handling
     * the summary information. An additional feature, however, are the
     * custom properties. */

    /* Read the document summary information. */
    DocumentSummaryInformation dsi;
    try {
        DocumentEntry dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
        DocumentInputStream dis = new DocumentInputStream(dsiEntry);
        PropertySet ps = new PropertySet(dis);
        dis.close();
        dsi = new DocumentSummaryInformation(ps);
    } catch (FileNotFoundException ex) {
        /* There is no document summary information yet. We have to create a
         * new one. */
        dsi = PropertySetFactory.newDocumentSummaryInformation();
    }

    /* Change the category to "POI example". Any former category value will
     * be lost. If there has been no category yet, it will be created. */
    dsi.setCategory("POI example");
    System.out.println("Category changed to " + dsi.getCategory() + ".");

    /* Read the custom properties. If there are no custom properties yet,
     * the application has to create a new CustomProperties object. It will
     * serve as a container for custom properties. */
    CustomProperties customProperties = dsi.getCustomProperties();
    if (customProperties == null)
        customProperties = new CustomProperties();

    /* Insert some custom properties into the container. */
    customProperties.put("Key 1", "Value 1");
    customProperties.put("Schl\u00fcssel 2", "Wert 2");
    customProperties.put("Sample Number", new Integer(12345));
    customProperties.put("Sample Boolean", Boolean.TRUE);
    customProperties.put("Sample Date", new Date());

    /* Read a custom property. */
    Object value = customProperties.get("Sample Number");

    /* Write the custom properties back to the document summary
     * information. */
    dsi.setCustomProperties(customProperties);

    /* Write the summary information and the document summary information
     * to the POI filesystem. */
    si.write(dir, SummaryInformation.DEFAULT_STREAM_NAME);
    dsi.write(dir, DocumentSummaryInformation.DEFAULT_STREAM_NAME);

    /* Write the POI filesystem back to the original file. Please note that
     * in production code you should never write directly to the origin
     * file! In case of a writing error everything would be lost. */
    OutputStream out = new FileOutputStream(poiFilesystem);
    poifs.writeFilesystem(out);
    out.close();
}

From source file:ro.nextreports.engine.exporter.XlsExporter.java

License:Apache License

public static void createSummaryInformation(String filePath, String title) {

    if (filePath == null) {
        return;/* w  w w  . j  a  v a  2 s .  c  om*/
    }
    try {
        File poiFilesystem = new File(filePath);
        InputStream is = new FileInputStream(poiFilesystem);
        POIFSFileSystem poifs = new POIFSFileSystem(is);
        is.close();
        DirectoryEntry dir = poifs.getRoot();

        SummaryInformation si = PropertySetFactory.newSummaryInformation();
        si.setTitle(title);
        si.setAuthor(ReleaseInfoAdapter.getCompany());
        si.setApplicationName("NextReports " + ReleaseInfoAdapter.getVersionNumber());
        si.setSubject("Created by NextReports Designer" + ReleaseInfoAdapter.getVersionNumber());
        si.setCreateDateTime(new Date());
        si.setKeywords(ReleaseInfoAdapter.getHome());

        si.write(dir, SummaryInformation.DEFAULT_STREAM_NAME);

        OutputStream out = new FileOutputStream(poiFilesystem);
        poifs.writeFilesystem(out);
        out.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:se.mithlond.services.content.impl.ejb.report.ExcelReportServiceBean.java

License:Apache License

/**
 * {@inheritDoc}//from ww w.ja va 2  s .  com
 */
@Override
public Workbook createDocument(@NotNull final Membership activeMembership, @NotNull final String title) {

    // Check sanity
    Validate.notNull(activeMembership, "activeMembership");

    final HSSFWorkbook toReturn = new HSSFWorkbook();
    toReturn.createInformationProperties();

    // Add some comments.
    final SummaryInformation summaryInformation = toReturn.getSummaryInformation();
    summaryInformation.setCreateDateTime(new Date());
    summaryInformation.setTitle(title);
    summaryInformation.setAuthor("Nazgl Services Excel Report Generator");
    summaryInformation.setSubject("Requested by: " + activeMembership.getAlias());
    summaryInformation.setRevNumber("1");

    // Add some Document summary information as well.
    final DocumentSummaryInformation documentSummaryInformation = toReturn.getDocumentSummaryInformation();
    final String orgName = activeMembership.getOrganisation().getOrganisationName();
    documentSummaryInformation.setCompany(activeMembership.getOrganisation().getOrganisationName());
    documentSummaryInformation.setManager(orgName + " is Da Boss of you!");

    // All Done.
    return toReturn;
}