List of usage examples for org.apache.poi.poifs.filesystem POIFSFileSystem POIFSFileSystem
public POIFSFileSystem(InputStream stream) throws IOException
From source file:com.hp.excelhandle.GetData.java
public ArrayList<Customer> loadCustomer() { ArrayList<Customer> listCustomer = new ArrayList(); try {/*www. j a va2 s . c o m*/ POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(mFileInput)); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); HSSFRow row; HSSFCell cell; int rows; // No of rows rows = sheet.getLastRowNum() + 1; //getPhysicalNumberOfRows(); System.out.println("ROWs number" + rows); System.out.println("Cell value: " + sheet.getRow(rows - 1).getCell(0)); int cols = 0; // No of columns (max) int temp = 0; // This trick ensures that we get the data properly even if it doesn't start from first few rows for (int i = 0; i < 10 || i < rows; i++) { row = sheet.getRow(i); if (row != null) { temp = sheet.getRow(i).getPhysicalNumberOfCells(); if (temp > cols) cols = temp; } } for (int i = 8; i < rows; i++) { row = sheet.getRow(i); if (row != null) { //If the customer id null if (row.getCell(ConfigFile.MA_DOI_TUONG_COL) == null || row.getCell(ConfigFile.X_COORDINATES_COL) == null || row.getCell(ConfigFile.Y_COORDINATES_COL) == null) { continue; } //Init Customer Object Customer custumer = new Customer(); custumer.setCoordinateX(row.getCell(ConfigFile.X_COORDINATES_COL).getNumericCellValue()); custumer.setCoordinateY(row.getCell(ConfigFile.Y_COORDINATES_COL).getNumericCellValue()); int tmp = 0; custumer.setStt((int) row.getCell(tmp++).getNumericCellValue()); custumer.setTinhThanh(row.getCell(tmp++).getStringCellValue()); custumer.setTuyenBanHangThu(row.getCell(tmp++).getStringCellValue()); custumer.setMaNhanVien(row.getCell(tmp++).getStringCellValue()); custumer.setX(row.getCell(tmp++).getStringCellValue()); custumer.setMaDoiTuong(row.getCell(tmp++).getStringCellValue()); custumer.setDoiTuong(row.getCell(tmp++).getStringCellValue()); // custumer.setmNoDKy(row.getCell(tmp++).getNumericCellValue()); // // custumer.setmCoDKy(row.getCell(tmp++).getNumericCellValue()); // custumer.setmNoTKy(row.getCell(tmp++).getNumericCellValue()); // custumer.setmTienBan(row.getCell(tmp++).getNumericCellValue()); // // custumer.setmCoTKy(row.getCell(tmp++).getNumericCellValue()); // custumer.setmCKGG(row.getCell(tmp++).getNumericCellValue()); // custumer.setmNhapLai(row.getCell(tmp++).getNumericCellValue()); // // custumer.setmNoCKy(row.getCell(tmp++).getNumericCellValue()); // custumer.setmCoCKy(row.getCell(tmp++).getNumericCellValue()); // custumer.setmDoanhThu(row.getCell(tmp++).getNumericCellValue()); // // custumer.setmPhanTramNoChiaThu(row.getCell(tmp++).getNumericCellValue()); // custumer.setmNoToiDa(row.getCell(tmp++).getNumericCellValue()); // custumer.setmDaiDien(row.getCell(tmp++).getStringCellValue()); custumer.setDiaChi(row.getCell(tmp++).getStringCellValue()); custumer.setDienThoai(row.getCell(tmp++).getStringCellValue()); custumer.setFax(row.getCell(tmp++).getStringCellValue()); custumer.setGhiChu(row.getCell(tmp++).getStringCellValue()); listCustomer.add(custumer); System.out.println("Add Object " + i); } } } catch (Exception ioe) { ioe.printStackTrace(); return null; } return listCustomer; }
From source file:com.hp.octane.integrations.uft.UftTestDiscoveryUtils.java
License:Apache License
private static String extractXmlContentFromTspFile(InputStream stream) throws IOException { POIFSFileSystem poiFS = new POIFSFileSystem(stream); DirectoryNode root = poiFS.getRoot(); String xmlData = ""; for (Entry entry : root) { String name = entry.getName(); if ("ComponentInfo".equals(name)) { if (entry instanceof DirectoryEntry) { System.out.println(entry); } else if (entry instanceof DocumentEntry) { byte[] content = new byte[((DocumentEntry) entry).getSize()]; int readBytes = poiFS.createDocumentInputStream("ComponentInfo").read(content); if (readBytes < content.length) { // [YG] probably should handle this case and continue to read logger.warn("expected to read " + content.length + " bytes, but read and stopped after " + readBytes); }//from ww w . ja va2s . c om String fromUnicodeLE = StringUtil.getFromUnicodeLE(content); xmlData = fromUnicodeLE.substring(fromUnicodeLE.indexOf('<')).replaceAll("\u0000", ""); } } } return xmlData; }
From source file:com.hpe.application.automation.tools.octane.actions.UFTTestUtil.java
License:Open Source License
public static String decodeXmlContent(InputStream stream) throws IOException { POIFSFileSystem poiFS = new POIFSFileSystem(stream); DirectoryNode root = poiFS.getRoot(); String xmlData = ""; for (Entry entry : root) { String name = entry.getName(); if ("ComponentInfo".equals(name)) { if (entry instanceof DirectoryEntry) { System.out.println(entry); } else if (entry instanceof DocumentEntry) { byte[] content = new byte[((DocumentEntry) entry).getSize()]; poiFS.createDocumentInputStream("ComponentInfo").read(content); String fromUnicodeLE = StringUtil.getFromUnicodeLE(content); xmlData = fromUnicodeLE.substring(fromUnicodeLE.indexOf('<')).replaceAll("\u0000", ""); }//from w w w . ja va 2 s . c o m } } return xmlData; }
From source file:com.impetus.kvapps.runner.UserBroker.java
License:Apache License
/** * Reads and populate a collection of {@link User} from excel file available at dataFilePath. * /*from w w w . j av a 2s.c o m*/ * @param dataFilePath * @return collection of users. */ static Set<User> brokeUserList(final String dataFilePath) { Set<User> users = new HashSet<User>(); Workbook workBook = null; File file = new File(dataFilePath); InputStream excelDocumentStream = null; try { excelDocumentStream = new FileInputStream(file); POIFSFileSystem fsPOI = new POIFSFileSystem(new BufferedInputStream(excelDocumentStream)); workBook = new HSSFWorkbook(fsPOI); UserBroker parser = new UserBroker(workBook.getSheetAt(0)); User user; while ((user = parser.addUser(users)) != null) { users.add(user); } excelDocumentStream.close(); } catch (Exception e) { throw new RuntimeException("Error while processing brokeUserList(), Caused by :", e); } return users; }
From source file:com.inet.web.service.mail.utils.ImportUtil.java
License:Open Source License
/** * Read content from given file//from w w w .j ava 2 s .c o m * @param fileInputStream * @return list of account * @throws BiffException * @throws IOException */ public static List<AccountImportInfo> readEmail(InputStream fileInputStream) throws Exception { try { POIFSFileSystem document = new POIFSFileSystem(fileInputStream); HSSFWorkbook workbook = new HSSFWorkbook(document); // Getting Default Sheet 0 HSSFSheet sheet = workbook.getSheetAt(0); HSSFRow rowData = null; String pwd = StringService.EMPTY_STRING; List<AccountImportInfo> infos = new ArrayList<AccountImportInfo>(); for (int i = 1;; i++) { // Get Individual Row rowData = sheet.getRow(i); if (rowData == null) break; // read data AccountImportInfo info = new AccountImportInfo(); info.setNumber(getLong(rowData, SEQUENCE)); info.setFullName(standardized(getString(rowData, FULLNAME))); info.setAccount(getString(rowData, EMAIL)); info.setLastName(standardized(getString(rowData, LASTNAME))); info.setMiddleName(standardized(getString(rowData, MIDDLENAME))); info.setFirstName(standardized(getString(rowData, FIRSTNAME))); pwd = getString(rowData, PASSWORD); if (!StringService.hasLength(pwd)) { pwd = info.getAccount(); info.setPassword(MailCommonUtils.getName(pwd)); } else { info.setPassword(pwd); } info.setPosition(getString(rowData, POSITION)); info.setTelephone(getString(rowData, TELEPHONE)); info.setMobile(getString(rowData, MOBILE)); info.setQuota(getLong(rowData, QUOTA)); infos.add(info); info.toString(); } return infos; } catch (Exception ex) { ex.printStackTrace(); throw ex; } }
From source file:com.ivstars.astrology.util.LocationProvider.java
License:Open Source License
public LocationProvider(InputStream in) throws IOException { POIFSFileSystem fs = new POIFSFileSystem(in); wb = new HSSFWorkbook(fs); }
From source file:com.jgaap.generics.DocumentHelper.java
License:Open Source License
/** * Extracts text from a Word document and stores it in the document. * /*from ww w . j a v a2s . c o m*/ * @param inputStream * An input stream pointing to the Word document to be read. * @throws IOException */ static private char[] loadMSWord(InputStream inputStream) throws IOException { POIFSFileSystem fs = new POIFSFileSystem(inputStream); HWPFDocument doc = new HWPFDocument(fs); WordExtractor we = new WordExtractor(doc); char[] origText = we.getText().toCharArray(); return origText; }
From source file:com.jk.framework.util.ExcelUtil.java
License:Apache License
/** * Parses the file./*from ww w.ja v a 2s . co m*/ * * @param selectedFile * the selected file * @param tableMeta * the table meta * @param headers * the headers * @return the array list * @throws ParserException * the parser exception */ // /////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static ArrayList<Record> parseFile(final InputStream selectedFile, final TableMeta tableMeta, final String... headers) throws ParserException { final ArrayList<Record> list = new ArrayList<Record>(); try { final POIFSFileSystem fs = new POIFSFileSystem(selectedFile); final HSSFWorkbook wb = new HSSFWorkbook(fs); final HSSFSheet sheet = wb.getSheetAt(0); final Iterator rows = sheet.rowIterator(); boolean firstRow = true; Hashtable<String, Integer> customHeaders = null; while (rows.hasNext()) { if (firstRow) { if (headers.length != 0) { customHeaders = processHeaders(headers, (HSSFRow) rows.next()); firstRow = false; } else { rows.next();// to skip first row firstRow = false; continue; } } list.add(populateRow(tableMeta, (HSSFRow) rows.next(), customHeaders)); } } catch (final Exception e) { throw new ParserException(e); } return list; }
From source file:com.jwm123.loggly.reporter.ReportGenerator.java
License:Apache License
public ReportGenerator(File reportFile) throws IOException, IllegalArgumentException { if (reportFile.exists()) { InputStream in = null;//from w ww. j a va 2 s .c om try { in = new FileInputStream(reportFile); if (reportFile.getName().endsWith(".xls")) { POIFSFileSystem fs = new POIFSFileSystem(in); workbook = new HSSFWorkbook(fs); } else if (reportFile.getName().endsWith(".xlsx")) { workbook = new XSSFWorkbook(in); } else { throw new IllegalArgumentException("Invalid report filename. " + reportFile.getName()); } } finally { IOUtils.closeQuietly(in); } } else { if (reportFile.getName().endsWith(".xls")) { workbook = new HSSFWorkbook(); } else if (reportFile.getName().endsWith(".xlsx")) { workbook = new XSSFWorkbook(); } else { throw new IllegalArgumentException("Invalid report filename. " + reportFile.getName()); } } }
From source file:com.kcs.action.FrfImportAction.java
public void excelToList() throws Exception { String filePath = getServletRequest().getSession().getServletContext().getRealPath("/"); try {/*from www .j a va 2 s . com*/ InputStream input = new BufferedInputStream(new FileInputStream(this.toBeUploaded)); POIFSFileSystem fs = new POIFSFileSystem(input); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); Iterator rows = sheet.rowIterator(); setResultsFromExcel(new ArrayList<Datasetfrf>()); int checkColName = 0; setCheckDatasetDate("true"); while (rows.hasNext()) { HSSFRow row = (HSSFRow) rows.next(); if (checkColName != 0) { Datasetfrf datasetfrf = new Datasetfrf(); Date dateFromJsp = DateUtil.convertDateFromJsp(getDataSetDate()); Date dateFromExcel = DateUtil.getDateFromString(row.getCell(1).toString(), DateUtil.DATE_FORMAT_YYYYMMDDX); if (dateFromJsp.compareTo(dateFromExcel) != 0) { setCheckDatasetDate("false"); break; } int index = 0; datasetfrf.setOrgId(row.getCell(index++).toString()); datasetfrf.setDataSetDate(convertDate(row.getCell(index++).toString())); datasetfrf.setLoanDepsitTrnTye(row.getCell(index++).toString()); datasetfrf.setCurrCode(row.getCell(index++).toString()); datasetfrf.setPaymentMethod(row.getCell(index++).toString()); datasetfrf.setBrOrBcFlg(row.getCell(index++).toString()); datasetfrf.setCommInLieuRate(row.getCell(index++).toString()); datasetfrf.setMinCommInLieu(row.getCell(index++).toString()); datasetfrf.setMaxCommInLieu(row.getCell(index++).toString()); datasetfrf.setOthFeeDesc(row.getCell(index++).toString()); datasetfrf.setEffectiveDate(convertDate(row.getCell(index++).toString())); datasetfrf.setEndDate(convertDate(row.getCell(index++).toString())); datasetfrf.setSeq(Long.valueOf(row.getCell(index++).toString())); datasetfrf.setUpdBy(getCurrentLoginId()); datasetfrf.setUpdDate(DateUtil.getCurrentDateTime()); index++; index++; datasetfrf.setSysCode(row.getCell(index++).toString()); getResultsFromExcel().add(datasetfrf); } checkColName++; } setResultsFromExcel(getResultsFromExcel()); session.put("EXCEL_TO_LIST_FRF", getResultsFromExcel()); } catch (IOException ex) { ex.printStackTrace(); logger.error("Error >>> " + ex.getMessage()); } }