List of usage examples for org.apache.poi.hssf.usermodel HSSFCell getStringCellValue
public String getStringCellValue()
From source file:com.efficio.fieldbook.web.nursery.service.impl.ExcelImportStudyServiceImpl.java
License:Open Source License
private int findRow(HSSFSheet sheet, String cellValue) { int result = 0; for (int i = 0; i < sheet.getLastRowNum(); i++) { HSSFRow row = sheet.getRow(i);/*w w w. j ava 2 s. com*/ if (row != null) { HSSFCell cell = row.getCell(0); if (cell != null && cell.getStringCellValue() != null) { if (cell.getStringCellValue().equals(cellValue)) { return i; } } } } return result; }
From source file:com.efficio.fieldbook.web.nursery.service.impl.ExcelImportStudyServiceImpl.java
License:Open Source License
private int findColumn(HSSFSheet sheet, String cellValue) { int result = -1; if (cellValue != null) { HSSFRow row = sheet.getRow(0); //Encabezados int cells = row.getLastCellNum(); for (int i = 0; i < cells; i++) { HSSFCell cell = row.getCell(i); if (cell.getStringCellValue().equals(cellValue)) { return i; }/* w w w . ja va 2s. c o m*/ } } return result; }
From source file:com.elbeesee.poink.transreptor.HSSFCellToXML.java
License:Open Source License
public void onTransrept(INKFRequestContext aContext) throws Exception { IHSSFCellRepresentation aIHSSFCellRepresentation = (IHSSFCellRepresentation) aContext .sourcePrimary(IHSSFCellRepresentation.class); HSSFCell vCell = aIHSSFCellRepresentation.getCellReadOnly(); String vSheetName = vCell.getSheet().getSheetName(); StringBuilder vCellXML = new StringBuilder(); vCellXML.append("<cell columnIndex=\""); vCellXML.append(vCell.getColumnIndex()); vCellXML.append("\" rowIndex=\""); vCellXML.append(vCell.getRow().getRowNum()); vCellXML.append("\" sheetIndex=\""); vCellXML.append(vCell.getSheet().getWorkbook().getSheetIndex(vSheetName)); vCellXML.append("\">"); int vCellType = vCell.getCellType(); if (vCellType == Cell.CELL_TYPE_FORMULA) { vCellType = vCell.getCachedFormulaResultType(); }/*from w w w .j ava 2 s . c o m*/ if (vCellType == Cell.CELL_TYPE_NUMERIC) { if (HSSFDateUtil.isCellDateFormatted(vCell)) { vCellXML.append(vCell.getDateCellValue()); } else { vCellXML.append(vCell.getNumericCellValue()); } } else if (vCellType == Cell.CELL_TYPE_STRING) { vCellXML.append(XMLUtils.escape(vCell.getStringCellValue())); } else if (vCellType == Cell.CELL_TYPE_BOOLEAN) { vCellXML.append(vCell.getBooleanCellValue()); } else if (vCellType == Cell.CELL_TYPE_BLANK) { } else if (vCellType == Cell.CELL_TYPE_ERROR) { vCellXML.append(vCell.getErrorCellValue()); } // vCellXML.append("</cell>"); INKFResponse vResponse = aContext.createResponseFrom(vCellXML.toString()); vResponse.setExpiry(INKFResponse.EXPIRY_DEPENDENT); }
From source file:com.essa.main.ReadExcel.java
public static void main(String[] args) { try {/*from w w w . j a va 2 s.c o m*/ InputStream input = new BufferedInputStream(new FileInputStream("sample.xls")); POIFSFileSystem fs = new POIFSFileSystem(input); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); Iterator rows = sheet.rowIterator(); while (rows.hasNext()) { HSSFRow row = (HSSFRow) rows.next(); System.out.println("\n"); Iterator cells = row.cellIterator(); while (cells.hasNext()) { HSSFCell cell = (HSSFCell) cells.next(); if (HSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()) System.out.print(cell.getNumericCellValue() + " "); else if (HSSFCell.CELL_TYPE_STRING == cell.getCellType()) System.out.print(cell.getStringCellValue() + " "); else if (HSSFCell.CELL_TYPE_BOOLEAN == cell.getCellType()) System.out.print(cell.getBooleanCellValue() + " "); else if (HSSFCell.CELL_TYPE_BLANK == cell.getCellType()) System.out.print("BLANK "); else System.out.print("Unknown cell type"); } } } catch (IOException ex) { ex.printStackTrace(); } }
From source file:com.example.selenium.util.ApachePOIXLSReader.java
private static Object cellToObject(HSSFCell cell) { Object result;/*from w ww . jav a 2 s . c o m*/ switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: result = cell.getNumericCellValue(); break; case Cell.CELL_TYPE_STRING: result = cell.getStringCellValue(); break; case Cell.CELL_TYPE_BOOLEAN: result = cell.getBooleanCellValue(); break; case Cell.CELL_TYPE_FORMULA: result = cell.getCellFormula(); break; default: throw new RuntimeException("Unknown Cell Type"); } return result; }
From source file:com.flexive.extractor.ExcelExtractor.java
License:Open Source License
private void processSheet(HSSFSheet sheet) { try {// w ww . j av a2 s . c o m // Use the HFFS functions for the number of rows & columns int rowCount = sheet.getPhysicalNumberOfRows(); int colCount = sheet.getRow(0).getPhysicalNumberOfCells(); HSSFRow row; HSSFCell cell; String cellValue; for (int i = 0; i < rowCount; i++) { row = sheet.getRow(i); for (short j = 0; j < colCount; j++) { cell = row.getCell(j); if (cell != null) { try { switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_BOOLEAN: cellValue = String.valueOf(cell.getBooleanCellValue()); break; case HSSFCell.CELL_TYPE_NUMERIC: cellValue = String.valueOf(cell.getNumericCellValue()); break; case HSSFCell.CELL_TYPE_FORMULA: // Doesnt make much sense to index a cell formula cellValue = ""; break; case HSSFCell.CELL_TYPE_ERROR: cellValue = String.valueOf(cell.getErrorCellValue()); break; case HSSFCell.CELL_TYPE_BLANK: cellValue = ""; break; default: cellValue = cell.getStringCellValue(); } } catch (Exception exc) { cellValue = ""; } writer.write(FxSharedUtils.getBytes(cellValue)); } } } } catch (Exception eN) { System.out.println("Error reading sheet:" + eN.toString()); } }
From source file:com.frameworkset.platform.cms.searchmanager.extractors.CmsExtractorMsExcel.java
License:Open Source License
/** * Extracts the text from the Excel table content.<p> * /*from ww w . j ava 2 s. com*/ * @param in the document input stream * @return the extracted text * @throws IOException if something goes wring */ protected String extractTableContent(InputStream in) throws IOException { HSSFWorkbook excelWb = new HSSFWorkbook(in); StringBuffer result = new StringBuffer(4096); int numberOfSheets = excelWb.getNumberOfSheets(); for (int i = 0; i < numberOfSheets; i++) { HSSFSheet sheet = excelWb.getSheetAt(i); int numberOfRows = sheet.getPhysicalNumberOfRows(); if (numberOfRows > 0) { if (CmsStringUtil.isNotEmpty(excelWb.getSheetName(i))) { // append sheet name to content if (i > 0) { result.append("\n\n"); } result.append(excelWb.getSheetName(i).trim()); result.append(":\n\n"); } Iterator rowIt = sheet.rowIterator(); while (rowIt.hasNext()) { HSSFRow row = (HSSFRow) rowIt.next(); if (row != null) { boolean hasContent = false; Iterator it = row.cellIterator(); while (it.hasNext()) { HSSFCell cell = (HSSFCell) it.next(); String text = null; try { switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_BLANK: case HSSFCell.CELL_TYPE_ERROR: // ignore all blank or error cells break; case HSSFCell.CELL_TYPE_NUMERIC: text = Double.toString(cell.getNumericCellValue()); break; case HSSFCell.CELL_TYPE_BOOLEAN: text = Boolean.toString(cell.getBooleanCellValue()); break; case HSSFCell.CELL_TYPE_STRING: default: text = cell.getStringCellValue(); break; } } catch (Exception e) { // ignore this cell } if (CmsStringUtil.isNotEmpty(text)) { result.append(text.trim()); result.append(' '); hasContent = true; } } if (hasContent) { // append a newline at the end of each row that has content result.append('\n'); } } } } } return result.toString(); }
From source file:com.github.dougkelly88.FLIMPlateReaderGUI.SequencingClasses.Classes.FilterTableModel.java
public void loadFilterTableModelfromSpreadsheet() { ArrayList<FilterSetup> load = new ArrayList(); HSSFSheet worksheet = HCAFLIMPluginFrame.wbLoad.getSheet("SpectralSequencing"); int RowSize = worksheet.getPhysicalNumberOfRows(); for (int RowNum = 0; RowNum < RowSize - 1; RowNum++) { HSSFRow row = worksheet.getRow(RowNum + 1); HSSFCell cell0 = row.getCell(0); HSSFCell cell1 = row.getCell(1); HSSFCell cell2 = row.getCell(2); HSSFCell cell3 = row.getCell(3); HSSFCell cell4 = row.getCell(4); HSSFCell cell5 = row.getCell(5); HSSFCell cell6 = row.getCell(6); HSSFCell cell7 = row.getCell(7); String delayss = cell7.getStringCellValue(); // some initializations for changing String of numbers to arrayList int strLength = delayss.length(); int count = 0; ArrayList<Integer> delays = new ArrayList(); String findStr = ","; int lastIndex = 0; String label = null;/* w w w .java 2 s . co m*/ int labelInt = 0; int bbb = 0; // counting entries in txt file for property while (lastIndex != -1) { lastIndex = delayss.indexOf(findStr, lastIndex); if (lastIndex != -1) { count++; lastIndex += findStr.length(); } } String subStr1 = delayss.substring(1, strLength - 1); // writes every single value into arrayList for (int i = 0; i < count; i++) { bbb = subStr1.indexOf(","); label = subStr1.substring(0, bbb); labelInt = Integer.parseInt(label); delays.add(labelInt); subStr1 = subStr1.substring(bbb + 2); } // writes last entry label = subStr1; labelInt = Integer.parseInt(label); delays.add(labelInt); // FilterSetup fov = new FilterSetup( cell0.getStringCellValue(), cell1.getStringCellValue(), cell2.getStringCellValue(), cell3.getStringCellValue(), cell4.getStringCellValue(), cell5.getStringCellValue(), (int) cell6.getNumericCellValue(), delays); // load.add(fov); } data_ = load; fireTableDataChanged(); }
From source file:com.github.dougkelly88.FLIMPlateReaderGUI.SequencingClasses.Classes.FOVTableModel.java
public void loadFOVTableModelfromSpreadsheet() { ArrayList<FOV> load = new ArrayList(); HSSFSheet worksheet = HCAFLIMPluginFrame.wbLoad.getSheet("XYSequencing"); int RowSize = worksheet.getPhysicalNumberOfRows(); for (int RowNum = 0; RowNum < RowSize - 1; RowNum++) { HSSFRow row = worksheet.getRow(RowNum + 1); HSSFCell cell0 = row.getCell(0); HSSFCell cell1 = row.getCell(1); HSSFCell cell2 = row.getCell(2); HSSFCell cell3 = row.getCell(3); HSSFCell cell4 = row.getCell(4); FOV fov = new FOV(cell1.getNumericCellValue(), cell2.getNumericCellValue(), cell3.getNumericCellValue(), cell0.getStringCellValue(), pp_); fov.setGroup(cell4.getStringCellValue()); load.add(fov);/* w ww. j a v a 2 s .c om*/ } data_ = load; fireTableDataChanged(); }
From source file:com.glaf.base.modules.todo.TodoXlsReader.java
License:Apache License
public List<Todo> readXls(java.io.InputStream inputStream) { List<Todo> todos = new java.util.ArrayList<Todo>(); HSSFWorkbook wb = null;/*from ww w . j ava2 s . c o m*/ try { wb = new HSSFWorkbook(inputStream); } catch (Exception ex) { throw new RuntimeException(ex); } HSSFSheet sheet = wb.getSheetAt(0); HSSFRow row = sheet.getRow(1); Map<Integer, String> keyMap = new java.util.HashMap<Integer, String>(); Map<String, Object> dataMap = new java.util.HashMap<String, Object>(); int cells = row.getPhysicalNumberOfCells(); for (int colIndex = 0; colIndex < cells; colIndex++) { HSSFCell cell = row.getCell(colIndex); keyMap.put(colIndex, cell.getStringCellValue()); } Set<String> keys = new HashSet<String>(); for (int rowIndex = 2; rowIndex < sheet.getPhysicalNumberOfRows(); rowIndex++) { HSSFRow rowx = sheet.getRow(rowIndex); if (rowx == null) { continue; } // System.out.println(); dataMap.clear(); for (int colIndex = 0; colIndex < cells; colIndex++) { String fieldName = keyMap.get(colIndex); HSSFCell cell = rowx.getCell(colIndex); if (cell == null) { continue; } Object cellValue = null; switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_FORMULA: break; case HSSFCell.CELL_TYPE_BOOLEAN: cellValue = cell.getBooleanCellValue(); break; case HSSFCell.CELL_TYPE_NUMERIC: cellValue = cell.getNumericCellValue(); break; case HSSFCell.CELL_TYPE_STRING: if (StringUtils.isNotEmpty(cell.getRichStringCellValue().getString())) { cellValue = cell.getRichStringCellValue().getString(); } break; default: if (StringUtils.isNotEmpty(cell.getStringCellValue())) { cellValue = cell.getStringCellValue(); } break; } if (cellValue != null) { dataMap.put(fieldName, cellValue); if ("id".equals(fieldName)) { cellValue = cellValue.toString().substring(0, cellValue.toString().indexOf(".")); dataMap.put(fieldName, cellValue); } } } if (dataMap.get("code") != null) { String id = ParamUtils.getString(dataMap, "id"); if (!keys.contains(ParamUtils.getString(dataMap, "code"))) { if (id != null && StringUtils.isNotEmpty(id)) { Todo model = new Todo(); Tools.populate(model, dataMap); if (ParamUtils.getInt(dataMap, "limitDay") > 0) { model.setLimitDay(ParamUtils.getInt(dataMap, "limitDay")); } todos.add(model); keys.add(model.getCode()); } } } } return todos; }