List of usage examples for org.apache.poi.poifs.filesystem POIFSFileSystem POIFSFileSystem
public POIFSFileSystem(InputStream stream) throws IOException
From source file:net.sf.jasperreports.engine.export.JRXlsMetadataExporter.java
License:Open Source License
protected void openWorkbook(OutputStream os) throws JRException { XlsMetadataExporterConfiguration configuration = getCurrentConfiguration(); String lcWorkbookTemplate = workbookTemplate == null ? configuration.getWorkbookTemplate() : workbookTemplate;/*from w w w . j a v a 2 s . c o m*/ if (lcWorkbookTemplate == null) { workbook = new HSSFWorkbook(); } else { InputStream templateIs = null; try { templateIs = RepositoryUtil.getInstance(jasperReportsContext) .getInputStreamFromLocation(lcWorkbookTemplate); if (templateIs == null) { throw new JRRuntimeException("Workbook template not found at : " + lcWorkbookTemplate); } else { workbook = new HSSFWorkbook(new POIFSFileSystem(templateIs)); boolean keepSheets = keepTemplateSheets == null ? configuration.isKeepWorkbookTemplateSheets() : keepTemplateSheets; if (keepSheets) { sheetIndex += workbook.getNumberOfSheets(); } else { for (int i = 0; i < workbook.getNumberOfSheets(); i++) { workbook.removeSheetAt(i); } } } } catch (JRException e) { throw new JRRuntimeException(e); } catch (IOException e) { throw new JRRuntimeException(e); } finally { if (templateIs != null) { try { templateIs.close(); } catch (IOException e) { } } } } emptyCellStyle = workbook.createCellStyle(); emptyCellStyle.setFillForegroundColor((new HSSFColor.WHITE()).getIndex()); emptyCellStyle.setFillPattern(backgroundMode); dataFormat = workbook.createDataFormat(); createHelper = workbook.getCreationHelper(); firstPageNotSet = true; palette = workbook.getCustomPalette(); customColorIndex = MIN_COLOR_INDEX; columnWidths = new HashMap<String, Integer>(); }
From source file:net.sf.mmm.content.parser.impl.poi.AbstractContentParserPoi.java
License:Apache License
/** * {@inheritDoc}//from w w w. j av a2 s . c o m */ @Override public void parse(InputStream inputStream, long filesize, ContentParserOptions options, MutableGenericContext context) throws Exception { POIFSFileSystem poiFs = new POIFSFileSystem(inputStream); SummaryInformation summaryInfo = (SummaryInformation) PropertySetFactory .create(poiFs.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME)); String title = summaryInfo.getTitle(); if (title != null) { context.setVariable(VARIABLE_NAME_TITLE, title); } String author = summaryInfo.getAuthor(); if (author != null) { context.setVariable(VARIABLE_NAME_CREATOR, author); } String keywords = summaryInfo.getKeywords(); if (keywords != null) { context.setVariable(VARIABLE_NAME_KEYWORDS, keywords); } context.setVariable(VARIABLE_NAME_TEXT, extractText(poiFs, filesize, options)); }
From source file:net.sf.mpxj.explorer.PoiTreeController.java
License:Open Source License
/** * Command to load a file.//from w w w. ja va2s . c om * * @param file file to load */ public void loadFile(File file) { InputStream is = null; try { is = new FileInputStream(file); POIFSFileSystem fs = new POIFSFileSystem(is); m_model.setFile(fs); } catch (IOException ex) { throw new RuntimeException(ex); } finally { if (is != null) { try { is.close(); } catch (IOException ex) { // Do nothing } } } }
From source file:net.sf.mpxj.mpp.MPPReader.java
License:Open Source License
/** * {@inheritDoc}//from w ww . j a va 2s. co m */ @Override public ProjectFile read(InputStream is) throws MPXJException { try { // // Open the file system // POIFSFileSystem fs = new POIFSFileSystem(is); return read(fs); } catch (IOException ex) { throw new MPXJException(MPXJException.READ_ERROR, ex); } }
From source file:net.sf.mpxj.reader.UniversalProjectReader.java
License:Open Source License
/** * We have an OLE compound document... but is it an MPP file? * * @param stream file input stream//w ww . j av a 2 s .c o m * @return ProjectFile instance */ private ProjectFile handleOleCompoundDocument(InputStream stream) throws Exception { POIFSFileSystem fs = new POIFSFileSystem(POIFSFileSystem.createNonClosingInputStream(stream)); String fileFormat = MPPReader.getFileFormat(fs); if (fileFormat != null && fileFormat.startsWith("MSProject")) { MPPReader reader = new MPPReader(); addListeners(reader); return reader.read(fs); } return null; }
From source file:net.sf.mpxj.sample.MppDump.java
License:Open Source License
/** * This method opens the input and output files and kicks * off the processing./*w w w . j a v a 2s . co m*/ * * @param input Name of the input file * @param output Name of the output file * @throws Exception Thrown on file read errors */ private static void process(String input, String output) throws Exception { FileInputStream is = new FileInputStream(input); PrintWriter pw = new PrintWriter(new FileWriter(output)); POIFSFileSystem fs = new POIFSFileSystem(is); dumpTree(pw, fs.getRoot(), "", true, true, null); is.close(); pw.flush(); pw.close(); }
From source file:net.sf.mpxj.utility.MppClean.java
License:Open Source License
/** * Process an MPP file to make it anonymous. * //from ww w . j ava 2 s.com * @param input input file name * @param output output file name * @throws Exception */ private void process(String input, String output) throws MPXJException, IOException { // // Extract the project data // MPPReader reader = new MPPReader(); m_project = reader.read(input); String varDataFileName; String projectDirName; switch (m_project.getMppFileType()) { case 8: { projectDirName = " 1"; varDataFileName = "FixDeferFix 0"; break; } case 9: { projectDirName = " 19"; varDataFileName = "Var2Data"; break; } case 12: { projectDirName = " 112"; varDataFileName = "Var2Data"; break; } default: { throw new IllegalArgumentException("Unsupported file type " + m_project.getMppFileType()); } } // // Load the raw file // FileInputStream is = new FileInputStream(input); POIFSFileSystem fs = new POIFSFileSystem(is); is.close(); // // Locate the root of the project file system // DirectoryEntry root = fs.getRoot(); m_projectDir = (DirectoryEntry) root.getEntry(projectDirName); // // Process Tasks // Map<String, String> replacements = new HashMap<String, String>(); for (Task task : m_project.getAllTasks()) { mapText(task.getName(), replacements); } processReplacements(((DirectoryEntry) m_projectDir.getEntry("TBkndTask")), varDataFileName, replacements, true); // // Process Resources // replacements.clear(); for (Resource resource : m_project.getAllResources()) { mapText(resource.getName(), replacements); mapText(resource.getInitials(), replacements); } processReplacements((DirectoryEntry) m_projectDir.getEntry("TBkndRsc"), varDataFileName, replacements, true); // // Process project header details // replacements.clear(); ProjectHeader header = m_project.getProjectHeader(); mapText(header.getProjectTitle(), replacements); processReplacements(m_projectDir, "Props", replacements, true); replacements.clear(); mapText(header.getProjectTitle(), replacements); mapText(header.getSubject(), replacements); mapText(header.getAuthor(), replacements); mapText(header.getKeywords(), replacements); mapText(header.getComments(), replacements); processReplacements(root, "\005SummaryInformation", replacements, false); replacements.clear(); mapText(header.getManager(), replacements); mapText(header.getCompany(), replacements); mapText(header.getCategory(), replacements); processReplacements(root, "\005DocumentSummaryInformation", replacements, false); // // Write the replacement raw file // FileOutputStream os = new FileOutputStream(output); fs.writeFilesystem(os); os.flush(); os.close(); }
From source file:net.sf.mpxj.utility.MppCleanUtility.java
License:Open Source License
/** * Process an MPP file to make it anonymous. * // ww w .j a v a2s . c o m * @param input input file name * @param output output file name * @throws Exception */ private void process(String input, String output) throws MPXJException, IOException { // // Extract the project data // MPPReader reader = new MPPReader(); m_project = reader.read(input); String varDataFileName; String projectDirName; int mppFileType = NumberHelper.getInt(m_project.getProjectProperties().getMppFileType()); switch (mppFileType) { case 8: { projectDirName = " 1"; varDataFileName = "FixDeferFix 0"; break; } case 9: { projectDirName = " 19"; varDataFileName = "Var2Data"; break; } case 12: { projectDirName = " 112"; varDataFileName = "Var2Data"; break; } default: { throw new IllegalArgumentException("Unsupported file type " + mppFileType); } } // // Load the raw file // FileInputStream is = new FileInputStream(input); POIFSFileSystem fs = new POIFSFileSystem(is); is.close(); // // Locate the root of the project file system // DirectoryEntry root = fs.getRoot(); m_projectDir = (DirectoryEntry) root.getEntry(projectDirName); // // Process Tasks // Map<String, String> replacements = new HashMap<String, String>(); for (Task task : m_project.getAllTasks()) { mapText(task.getName(), replacements); } processReplacements(((DirectoryEntry) m_projectDir.getEntry("TBkndTask")), varDataFileName, replacements, true); // // Process Resources // replacements.clear(); for (Resource resource : m_project.getAllResources()) { mapText(resource.getName(), replacements); mapText(resource.getInitials(), replacements); } processReplacements((DirectoryEntry) m_projectDir.getEntry("TBkndRsc"), varDataFileName, replacements, true); // // Process project properties // replacements.clear(); ProjectProperties properties = m_project.getProjectProperties(); mapText(properties.getProjectTitle(), replacements); processReplacements(m_projectDir, "Props", replacements, true); replacements.clear(); mapText(properties.getProjectTitle(), replacements); mapText(properties.getSubject(), replacements); mapText(properties.getAuthor(), replacements); mapText(properties.getKeywords(), replacements); mapText(properties.getComments(), replacements); processReplacements(root, "\005SummaryInformation", replacements, false); replacements.clear(); mapText(properties.getManager(), replacements); mapText(properties.getCompany(), replacements); mapText(properties.getCategory(), replacements); processReplacements(root, "\005DocumentSummaryInformation", replacements, false); // // Write the replacement raw file // FileOutputStream os = new FileOutputStream(output); fs.writeFilesystem(os); os.flush(); os.close(); }
From source file:net.sourceforge.docfetcher.model.parse.MSExcelParser.java
License:Open Source License
protected String renderText(File file, String filename) throws ParseException { InputStream in = null;//from ww w.j a v a 2s . com try { in = new FileInputStream(file); ExcelExtractor extractor = null; try { POIFSFileSystem fs = new POIFSFileSystem(in); extractor = new ExcelExtractor(fs); extractor.setFormulasNotResults(ProgramConf.Bool.IndexExcelFormulas.get()); return extractor.getText(); } catch (OldExcelFormatException e) { /* * POI doesn't support the old Excel 5.0/7.0 (BIFF5) format, * only the BIFF8 format from Excel 97/2000/XP/2003. Thus, we * fall back to another Excel library. */ Closeables.closeQuietly(in); return extractWithJexcelAPI(file); } finally { Closeables.closeQuietly(extractor); } } catch (IOException e) { throw new ParseException(e); } catch (RuntimeException e) { // POI can throw NullPointerExceptions on some odd Excel files throw new ParseException(e); } finally { Closeables.closeQuietly(in); } }
From source file:net.sourceforge.docfetcher.parse.MSExcelParser.java
License:Open Source License
public String renderText(File file) throws ParseException { InputStream in = null;/*from ww w . ja v a2 s. co m*/ try { in = new FileInputStream(file); ExcelExtractor extractor = null; try { POIFSFileSystem fs = new POIFSFileSystem(in); extractor = new ExcelExtractor(fs); } catch (OldExcelFormatException e) { /* * POI doesn't support the old Excel 5.0/7.0 (BIFF5) format, * only the BIFF8 format from Excel 97/2000/XP/2003. Thus, we * fall back to another Excel library. */ in.close(); return extractWithJexcelAPI(file); } catch (Exception e) { // This can happen if the file has the "xls" extension, but is not an Excel document throw new ParseException(file, Msg.file_corrupted.value()); } finally { in.close(); } extractor.setFormulasNotResults(true); return extractor.getText(); } catch (FileNotFoundException e) { throw new ParseException(file, Msg.file_not_found.value()); } catch (IOException e) { throw new ParseException(file, Msg.file_not_readable.value()); } }