/** * Writes a {@link PropertySet} to a POI filesystem. * * @param poiFs The POI filesystem to write to. * @param path The file's path in the POI filesystem. * @param name The file's name in the POI filesystem. * @param ps The property set to write. * @throws WritingNotSupportedException * @throws IOException */ public void copy( final POIFSFileSystem poiFs, final POIFSDocumentPath path, final String name, final PropertySet ps) throws WritingNotSupportedException, IOException { final DirectoryEntry de = getPath(poiFs, path); final MutablePropertySet mps = new MutablePropertySet(ps); de.createDocument(name, mps.toInputStream()); }
protected HSSFWorkbook makeWorkbook(final Report report, final ELContext ctx) throws Exception { final byte[] emptyWorkbookData = new HSSFWorkbook().getBytes(); final POIFSFileSystem fs; if (report.getTemplate() != null) { fs = new POIFSFileSystem(new ByteArrayInputStream(report.getTemplate())); } else { fs = new POIFSFileSystem(); fs.createDocument(new ByteArrayInputStream(emptyWorkbookData), "Workbook"); } final MutablePropertySet siProperties = new MutablePropertySet(); final MutableSection siSection = (MutableSection) siProperties.getSections().get(0); siSection.setFormatID(SectionIDMap.SUMMARY_INFORMATION_ID); final MutableProperty p0 = new MutableProperty(); p0.setID(PropertyIDMap.PID_CREATE_DTM); p0.setType(Variant.VT_FILETIME); p0.setValue(new Date()); siSection.setProperty(p0); final String application = report.getDescription().getApplication(ctx); if (application != null) { final MutableProperty p = new MutableProperty(); p.setID(PropertyIDMap.PID_APPNAME); p.setType(Variant.VT_LPWSTR); p.setValue(application); siSection.setProperty(p); } final String author = report.getDescription().getAuthor(ctx); if (author != null) { final MutableProperty p = new MutableProperty(); p.setID(PropertyIDMap.PID_AUTHOR); p.setType(Variant.VT_LPWSTR); p.setValue(author); siSection.setProperty(p); } final String version = report.getDescription().getVersion(ctx); if (version != null) { final MutableProperty p = new MutableProperty(); p.setID(PropertyIDMap.PID_REVNUMBER); p.setType(Variant.VT_LPWSTR); p.setValue(version); siSection.setProperty(p); } final String title = report.getDescription().getTitle(ctx); if (title != null) { final MutableProperty p = new MutableProperty(); p.setID(PropertyIDMap.PID_TITLE); p.setType(Variant.VT_LPWSTR); p.setValue(title); siSection.setProperty(p); } final String subject = report.getDescription().getSubject(ctx); if (subject != null) { final MutableProperty p = new MutableProperty(); p.setID(PropertyIDMap.PID_SUBJECT); p.setType(Variant.VT_LPWSTR); p.setValue(subject); siSection.setProperty(p); } final String comments = report.getDescription().getComments(ctx); if (comments != null) { final MutableProperty p = new MutableProperty(); p.setID(PropertyIDMap.PID_COMMENTS); p.setType(Variant.VT_LPWSTR); p.setValue(comments); siSection.setProperty(p); } final MutablePropertySet dsiProperties = new MutablePropertySet(); final MutableSection dsiSection = (MutableSection) dsiProperties.getSections().get(0); dsiSection.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[0]); final String company = report.getDescription().getCompany(ctx); if (company != null) { final MutableProperty p = new MutableProperty(); p.setID(PropertyIDMap.PID_COMPANY); p.setType(Variant.VT_LPWSTR); p.setValue(company); dsiSection.setProperty(p); } final String category = report.getDescription().getCategory(ctx); if (category != null) { final MutableProperty p = new MutableProperty(); p.setID(PropertyIDMap.PID_CATEGORY); p.setType(Variant.VT_LPWSTR); p.setValue(category); dsiSection.setProperty(p); } fs.createDocument(siProperties.toInputStream(), SummaryInformation.DEFAULT_STREAM_NAME); fs.createDocument( dsiProperties.toInputStream(), DocumentSummaryInformation.DEFAULT_STREAM_NAME); return new HSSFWorkbook(fs, true); }