List of usage examples for org.apache.poi.poifs.filesystem POIFSFileSystem POIFSFileSystem
public POIFSFileSystem(InputStream stream) throws IOException
From source file:edu.tsinghua.lumaqq.customface.EIPImporter.java
License:Open Source License
@SuppressWarnings("unchecked") public EIPImporter(String file, String destDir) { this.destDir = destDir; buffer = new byte[8192]; POIFSFileSystem eipSystem;/*ww w. j av a 2 s . co m*/ try { // eip eipStream = new FileInputStream(file); eipSystem = new POIFSFileSystem(eipStream); // DirectoryEntry configDir = null, fileDir = null; DirectoryEntry root = eipSystem.getRoot(); Iterator<Entry> i = root.getEntries(); while (i.hasNext()) { Entry e = i.next(); if (e.isDirectoryEntry()) { if (CONFIG_DIRECTORY.equals(e.getName().toLowerCase())) configDir = (DirectoryEntry) e; else if (FILES_DIRECTORY.equals(e.getName().toLowerCase())) fileDir = (DirectoryEntry) e; } } // ?? if (configDir == null || fileDir == null) throw new IOException("Can't find correct directories"); // ?face.xml i = configDir.getEntries(); while (i.hasNext()) { Entry e = i.next(); if (e.isDocumentEntry() && CONFIG_FILE.equals(e.getName().toLowerCase())) { DocumentInputStream dis = new DocumentInputStream((DocumentEntry) e); parser = new FaceXMLParser(dis); dis.close(); break; } } // ??face.xml if (parser == null) throw new IOException("Can't find " + CONFIG_FILE); // iterator groupIterator = fileDir.getEntries(); currentDir = fileDir; faceIterator = currentDir.getEntries(); } catch (IOException e) { eipSystem = null; try { if (eipStream != null) { eipStream.close(); eipStream = null; } } catch (IOException e1) { } } }
From source file:edu.ucsd.bioeng.coreplugin.tableImport.tests.ExcelAttributeSheetReaderTest.java
License:Open Source License
/** * DOCUMENT ME!//from ww w.j a va2 s . c om * * @throws Exception DOCUMENT ME! */ public void testReadTable() throws Exception { /* * Load test network */ CyNetwork net = Cytoscape.createNetworkFromURL(getClass().getResource(NETWORK_FILE), true); /* * Single Sheet Test */ InputStream is = null; POIFSFileSystem excelIn; try { is = getClass().getResource(WORKBOOK1).openStream(); excelIn = new POIFSFileSystem(is); } finally { if (is != null) { is.close(); } } HSSFWorkbook wb = new HSSFWorkbook(excelIn); HSSFSheet sheet = wb.getSheetAt(0); List<String> delimiters = new ArrayList<String>(); delimiters.add(TextFileDelimiters.TAB.toString()); List<Integer> aliasList = new ArrayList<Integer>(); aliasList.add(2); String[] galAttrName = { "ID", "ID in SGD", "Synonyms", "Description of Genes", "Date", "Sample Boolean Attr2", "gal1RGexp", "gal1RGsig", "String List" }; Byte[] galAttrTypes = { CyAttributes.TYPE_STRING, CyAttributes.TYPE_STRING, CyAttributes.TYPE_STRING, CyAttributes.TYPE_STRING, CyAttributes.TYPE_INTEGER, CyAttributes.TYPE_BOOLEAN, CyAttributes.TYPE_FLOATING, CyAttributes.TYPE_FLOATING, CyAttributes.TYPE_SIMPLE_LIST }; for (int i = 0; i < galAttrTypes.length; i++) { System.out.println("GAL Data Type " + i + " = " + galAttrTypes[i]); } AttributeMappingParameters mapping = new AttributeMappingParameters(TextTableReader.ObjectType.NODE, null, COMMA.toString(), 0, "ID", aliasList, galAttrName, galAttrTypes, null, null); TextTableReader rd = new ExcelAttributeSheetReader(sheet, mapping, 0); rd.readTable(); assertEquals("ribosomal protein S28A (S33A) (YS27)", Cytoscape.getNodeAttributes().getStringAttribute("YOR167C", "Description of Genes")); assertEquals(new Integer(20010118), Cytoscape.getNodeAttributes().getIntegerAttribute("YHR141C", "Date")); //assertEquals(4, Cytoscape.getNodeAttributes().getListAttribute("YER112W", "alias").size()); /* * Multiple sheet test (not yet supported) */ Cytoscape.destroyNetwork(net); }
From source file:edu.ucsd.bioeng.coreplugin.tableImport.tests.ExcelNetworkSheetReaderTest.java
License:Open Source License
/** * DOCUMENT ME!// w w w .j a va 2 s.co m * * @throws Exception DOCUMENT ME! */ public void testReadTable() throws Exception { InputStream is = null; POIFSFileSystem excelIn; try { is = getClass().getResource(NETWORK_FILE).openStream(); excelIn = new POIFSFileSystem(is); } finally { if (is != null) { is.close(); } } HSSFWorkbook wb = new HSSFWorkbook(excelIn); HSSFSheet sheet = wb.getSheetAt(0); List<String> delimiters = new ArrayList<String>(); delimiters.add(TextFileDelimiters.TAB.toString()); String[] galAttrName = { "Source", "Target", "Interaction", "edge bool attr", "edge string attr", "edge float attr" }; Byte[] galAttrTypes = { CyAttributes.TYPE_STRING, CyAttributes.TYPE_STRING, CyAttributes.TYPE_STRING, CyAttributes.TYPE_BOOLEAN, CyAttributes.TYPE_STRING, CyAttributes.TYPE_FLOATING }; NetworkTableMappingParameters mapping = new NetworkTableMappingParameters(delimiters, TextFileDelimiters.PIPE.toString(), galAttrName, galAttrTypes, null, null, 0, 1, 2, null); reader = new ExcelNetworkSheetReader(wb.getSheetName(0), sheet, mapping); CyNetwork net = Cytoscape.createNetwork(reader, false, null); /* * test cases */ assertEquals("Yeast Network Sheet 1", net.getTitle()); assertEquals(331, net.getNodeCount()); assertEquals(362, net.getEdgeCount()); CyAttributes attr = Cytoscape.getEdgeAttributes(); assertTrue(attr.getBooleanAttribute("YGL122C (pp) YOL123W", "edge bool attr")); assertFalse(attr.getBooleanAttribute("YKR026C (pp) YGL122C", "edge bool attr")); assertEquals(1.2344543, attr.getDoubleAttribute("YBL026W (pp) YOR167C", "edge float attr")); assertEquals("abcd12706", attr.getStringAttribute("YBL026W (pp) YOR167C", "edge string attr")); assertEquals("abcd12584", attr.getStringAttribute("YPL248C (pd) ?", "edge string attr")); Cytoscape.destroyNetwork(net); }
From source file:edu.ucsd.bioeng.coreplugin.tableImport.tests.ExcelNetworkSheetReaderTest.java
License:Open Source License
public void testReadTableWithEmptyRows() throws Exception { String network = "/empty_attr_row.xls"; InputStream is = null;//www .java 2 s .c o m POIFSFileSystem excelIn; try { is = getClass().getResource(network).openStream(); excelIn = new POIFSFileSystem(is); } finally { if (is != null) { is.close(); } } HSSFWorkbook wb = new HSSFWorkbook(excelIn); HSSFSheet sheet = wb.getSheetAt(0); List<String> delimiters = new ArrayList<String>(); delimiters.add(TextFileDelimiters.TAB.toString()); String[] galAttrName = { "Gene 1", "Gene 2", "Interaction Type", "Gene", "GO Group" }; Byte[] galAttrTypes = { CyAttributes.TYPE_STRING, CyAttributes.TYPE_STRING, CyAttributes.TYPE_STRING, CyAttributes.TYPE_STRING, CyAttributes.TYPE_STRING }; NetworkTableMappingParameters mapping = new NetworkTableMappingParameters(delimiters, TextFileDelimiters.PIPE.toString(), galAttrName, galAttrTypes, null, null, 0, 1, 2, null); CyNetwork net = null; try { reader = new ExcelNetworkSheetReader(wb.getSheetName(0), sheet, mapping, 1); net = Cytoscape.createNetwork(reader, false, null); } catch (Exception ee) { ee.printStackTrace(); fail("Caught exception"); } assertEquals(222, net.getNodeCount()); assertEquals(443, net.getEdgeCount()); CyAttributes attr = Cytoscape.getEdgeAttributes(); // test some random edges assertEquals("cc", attr.getStringAttribute("YDR459C (cc) YNL271C", "interaction")); assertEquals("Transport", attr.getStringAttribute("YDR459C (cc) YNL271C", "GO Group")); assertEquals("YPR011C", attr.getStringAttribute("YDR459C (cc) YNL271C", "Gene")); assertNull(attr.getStringAttribute("YEL040W (cc) YER016W", "GO Group")); assertNull(attr.getStringAttribute("YEL040W (cc) YER016W", "Gene")); Cytoscape.destroyNetwork(net); }
From source file:egovframework.rte.fdl.excel.impl.EgovExcelServiceImpl.java
License:Apache License
/** * Template ?? ?./*www . j a v a 2s . co m*/ * * @param templateName * @return * @throws Exception */ public Workbook loadExcelTemplate(String templateName) throws BaseException, FileNotFoundException, IOException { FileInputStream fileIn = new FileInputStream(templateName); Workbook wb = null; LOGGER.debug("EgovExcelServiceImpl.loadExcelTemplate : templatePath is {}", templateName); try { LOGGER.debug("ExcelServiceImpl loadExcelTemplate ..."); POIFSFileSystem fs = new POIFSFileSystem(fileIn); wb = new HSSFWorkbook(fs); } catch (Exception e) { LOGGER.error(getMessageSource().getMessage("error.excel.runtime.error", new Object[] { "EgovExcelServiceImpl loadExcelTemplate" }, Locale.getDefault()), e); } finally { LOGGER.debug("ExcelServiceImpl loadExcelTemplate end..."); fileIn.close(); } return wb; }
From source file:egovframework.rte.fdl.excel.impl.EgovExcelServiceImpl.java
License:Apache License
/** * ?? ./*w ww . j a v a 2 s .co m*/ * * @param filepath * @return * @throws Exception */ public Workbook loadWorkbook(InputStream fileIn) throws BaseException { Workbook wb = null; try { LOGGER.debug("ExcelServiceImpl loadWorkbook ..."); POIFSFileSystem fs = new POIFSFileSystem(fileIn); wb = new HSSFWorkbook(fs); } catch (Exception e) { LOGGER.error(getMessageSource().getMessage("error.excel.runtime.error", new Object[] { "loadWorkbook" }, Locale.getDefault()), e); } return wb; }
From source file:eionet.gdem.conversion.excel.ExcelUtils.java
License:Mozilla Public License
/** * Returns true, if InputStream can be opened with MS Excel. * @param input InputStream// w w w . j av a2s . c om * @return True, if InputStream can be opened with MS Excel. */ public static boolean isExcelFile(InputStream input) { try { POIFSFileSystem fs = new POIFSFileSystem(input); return true; } catch (Exception e) { return false; } finally { IOUtils.closeQuietly(input); } }
From source file:eionet.gdem.conversion.excel.reader.ExcelReader.java
License:Mozilla Public License
@Override public void initReader(File inputFile) throws GDEMException { if (inputFile == null) { throw new GDEMException("Input file is missing"); }/*w ww.j av a2 s . co m*/ try { if (!isExcel2007) { POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(inputFile)); wb = new HSSFWorkbook(fs); } else { OPCPackage p = OPCPackage.open(new FileInputStream(inputFile)); wb = WorkbookFactory.create(p); } } catch (Exception e) { throw new GDEMException("ErrorConversionHandler - couldn't open Excel file: " + e.toString()); } inputFileLength = inputFile.length(); evaluator = wb.getCreationHelper().createFormulaEvaluator(); }
From source file:endrov.customData.ImportTable.java
License:BSD License
/** * Import Excel file/*from ww w . j a va2s. c om*/ */ public void importExcel(String filename) throws Exception { rows.clear(); POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename)); HSSFWorkbook wb = new HSSFWorkbook(fs); //Take first sheet HSSFSheet sheet = wb.getSheetAt(0); for (int rowi = 0; sheet.getRow(rowi) != null; rowi++) { HSSFRow row = sheet.getRow(rowi); List<String> a = new LinkedList<String>(); for (int coli = 0; row.getCell((short) coli) != null; coli++) { HSSFCell c = row.getCell((short) coli); if (c.getCellType() == HSSFCell.CELL_TYPE_STRING) a.add(c.getRichStringCellValue().getString()); else if (c.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) a.add("" + c.getNumericCellValue()); } rows.add(a); } }
From source file:endrov.util.io.EvSpreadsheetImporter.java
License:BSD License
/** * Import Excel file/*from w w w . ja va2 s .co m*/ */ public void importExcel(String filename) throws Exception { rows.clear(); POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename)); HSSFWorkbook wb = new HSSFWorkbook(fs); //Take first sheet HSSFSheet sheet = wb.getSheetAt(0); int lastCapacity = 0; for (int rowi = 0; sheet.getRow(rowi) != null; rowi++) { HSSFRow row = sheet.getRow(rowi); ArrayList<String> a = new ArrayList<String>(lastCapacity); for (int coli = 0; row.getCell((short) coli) != null; coli++) { HSSFCell c = row.getCell((short) coli); if (c.getCellType() == HSSFCell.CELL_TYPE_STRING) a.add(c.getRichStringCellValue().getString()); else if (c.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) a.add("" + c.getNumericCellValue()); } rows.add(a); lastCapacity = a.size(); } }