Java Code Examples for org.apache.poi.xssf.usermodel.XSSFCell#getCellType()
The following examples show how to use
org.apache.poi.xssf.usermodel.XSSFCell#getCellType() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExcelDataProvider.java From xframium-java with GNU General Public License v3.0 | 6 votes |
/** * Gets the cell value. * * @param cell the cell * @return the cell value */ private String getCellValue( XSSFCell cell ) { if (cell != null) { switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_BLANK: return null; case XSSFCell.CELL_TYPE_BOOLEAN: return String.valueOf( cell.getBooleanCellValue() ); case XSSFCell.CELL_TYPE_NUMERIC: return String.valueOf( ( int ) cell.getNumericCellValue() ); case XSSFCell.CELL_TYPE_STRING: return cell.getRichStringCellValue().toString(); } } return null; }
Example 2
Source File: ExcelCloudProvider.java From xframium-java with GNU General Public License v3.0 | 6 votes |
/** * Gets the cell value. * * @param cell the cell * @return the cell value */ private String getCellValue( XSSFCell cell ) { if (cell != null) { switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_BLANK: return null; case XSSFCell.CELL_TYPE_BOOLEAN: return String.valueOf( cell.getBooleanCellValue() ); case XSSFCell.CELL_TYPE_NUMERIC: return String.valueOf( cell.getNumericCellValue() ); case XSSFCell.CELL_TYPE_STRING: return cell.getRichStringCellValue().toString(); } } return null; }
Example 3
Source File: ExcelApplicationProvider.java From xframium-java with GNU General Public License v3.0 | 6 votes |
/** * Gets the cell value. * * @param cell the cell * @return the cell value */ private String getCellValue( XSSFCell cell ) { if (cell != null) { switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_BLANK: return null; case XSSFCell.CELL_TYPE_BOOLEAN: return String.valueOf( cell.getBooleanCellValue() ); case XSSFCell.CELL_TYPE_NUMERIC: return String.valueOf( cell.getNumericCellValue() ); case XSSFCell.CELL_TYPE_STRING: return cell.getRichStringCellValue().toString(); } } return null; }
Example 4
Source File: ExcelContentProvider.java From xframium-java with GNU General Public License v3.0 | 6 votes |
/** * Gets the cell value. * * @param cell the cell * @return the cell value */ private String getCellValue( XSSFCell cell ) { if (cell != null) { switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_BLANK: return null; case XSSFCell.CELL_TYPE_BOOLEAN: return String.valueOf( cell.getBooleanCellValue() ); case XSSFCell.CELL_TYPE_NUMERIC: return String.valueOf( cell.getNumericCellValue() ); case XSSFCell.CELL_TYPE_STRING: return cell.getRichStringCellValue().toString(); } } return null; }
Example 5
Source File: ExcelElementProvider.java From xframium-java with GNU General Public License v3.0 | 6 votes |
/** * Gets the cell value. * * @param cell the cell * @return the cell value */ private String getCellValue( XSSFCell cell ) { if (cell != null) { switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_BLANK: return null; case XSSFCell.CELL_TYPE_BOOLEAN: return String.valueOf( cell.getBooleanCellValue() ); case XSSFCell.CELL_TYPE_NUMERIC: return String.valueOf( cell.getNumericCellValue() ); case XSSFCell.CELL_TYPE_STRING: return cell.getRichStringCellValue().toString(); } } return null; }
Example 6
Source File: ExcelPageDataProvider.java From xframium-java with GNU General Public License v3.0 | 6 votes |
/** * Gets the cell value. * * @param cell the cell * @return the cell value */ private String getCellValue( XSSFCell cell ) { if (cell != null) { switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_BLANK: return null; case XSSFCell.CELL_TYPE_BOOLEAN: return String.valueOf( cell.getBooleanCellValue() ); case XSSFCell.CELL_TYPE_NUMERIC: { String useValue = String.valueOf( cell.getNumericCellValue() ); if ( useValue.endsWith( ".0" ) ) return useValue.split( "\\." )[0]; else return useValue; } case XSSFCell.CELL_TYPE_STRING: return cell.getRichStringCellValue().toString(); } } return null; }
Example 7
Source File: ExcelKeyWordProvider.java From xframium-java with GNU General Public License v3.0 | 6 votes |
private String getCellValue( XSSFCell cell ) { if (cell != null ) { switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_BLANK: return null; case XSSFCell.CELL_TYPE_BOOLEAN: return String.valueOf( cell.getBooleanCellValue() ); case XSSFCell.CELL_TYPE_NUMERIC: return String.valueOf( cell.getNumericCellValue() ); case XSSFCell.CELL_TYPE_STRING: return cell.getRichStringCellValue().toString(); } } return null; }
Example 8
Source File: ExcelUtils.java From tianti with Apache License 2.0 | 5 votes |
private static String getValue(XSSFCell xssFCell) { String str = null; if(xssFCell == null){ return str; } if (xssFCell.getCellType() == XSSFCell.CELL_TYPE_BOOLEAN) { str = String.valueOf(xssFCell.getBooleanCellValue()); } else if (xssFCell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) { str = String.valueOf(new DecimalFormat("#").format(xssFCell.getNumericCellValue())); } else { str = String.valueOf(xssFCell.getStringCellValue()); } return StringUtils.trim(str); }
Example 9
Source File: ExcelComparator.java From data-prep with Apache License 2.0 | 5 votes |
public static boolean compareTwoCells(XSSFCell cell1, XSSFCell cell2) { if ((cell1 == null) && (cell2 == null)) { return true; } else if ((cell1 == null) || (cell2 == null)) { return false; } else if (cell1.getCellType() != cell2.getCellType()) { return false; } boolean equalCells = false; // Compare cells based on their type switch (cell1.getCellType()) { case FORMULA: equalCells = (cell1.getCellFormula().equals(cell2.getCellFormula())); break; case NUMERIC: equalCells = (cell1.getNumericCellValue() == cell2.getNumericCellValue()); break; case STRING: equalCells = (cell1.getStringCellValue().equals(cell2.getStringCellValue())); break; case BLANK: equalCells = true; break; case BOOLEAN: equalCells = (cell1.getBooleanCellValue() == cell2.getBooleanCellValue()); break; case ERROR: equalCells = (cell1.getErrorCellValue() == cell2.getErrorCellValue()); break; default: equalCells = (cell1.getStringCellValue().equals(cell2.getStringCellValue())); break; } return equalCells; }
Example 10
Source File: SpreadsheetTab.java From taro with MIT License | 5 votes |
public void autoSizeRow(int row) { float tallestCell = -1; for (int col = 0; col <= highestModifiedCol; col++) { SpreadsheetCell cell = getOrCreateCell(row, col); int fontSize = cell.getFontSizeInPoints(); XSSFCell poiCell = cell.getPoiCell(); if (poiCell.getCellType() == CellType.STRING) { String value = poiCell.getStringCellValue(); int numLines = 1; for (int i = 0; i < value.length(); i++) { if (value.charAt(i) == '\n') numLines++; } float cellHeight = computeRowHeightInPoints(fontSize, numLines); if (cellHeight > tallestCell) { tallestCell = cellHeight; } } } float defaultRowHeightInPoints = sheet.getDefaultRowHeightInPoints(); float rowHeight = tallestCell; if (rowHeight < defaultRowHeightInPoints+1) { rowHeight = -1; // resets to the default } sheet.getRow(row).setHeightInPoints(rowHeight); }
Example 11
Source File: readExcelXLSX.java From Selenium with The Unlicense | 5 votes |
private static String cellToString(XSSFCell cell) { Object result; 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.toString(); }
Example 12
Source File: ExcelServiceImpl.java From poi with Apache License 2.0 | 4 votes |
/** * 读取Office 2007 excel */ private List<List<Object>> readExcel2007(File file) throws IOException { List<List<Object>> list = new LinkedList<List<Object>>(); // 构造 XSSFWorkbook 对象,strPath 传入文件路径 XSSFWorkbook xwb = new XSSFWorkbook(new FileInputStream(file)); // 读取第一章表格内容 XSSFSheet sheet = xwb.getSheetAt(0); Object value = null; XSSFRow row = null; XSSFCell cell = null; int counter = 0; for (int i = sheet.getFirstRowNum(); counter < sheet .getPhysicalNumberOfRows(); i++) { row = sheet.getRow(i); if (row == null) { continue; } else { counter++; } List<Object> linked = new LinkedList<Object>(); for (int j = row.getFirstCellNum(); j <= row.getLastCellNum(); j++) { cell = row.getCell(j); if (cell == null) { continue; } DecimalFormat df = new DecimalFormat("0");// 格式化 number String // 字符 SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");// 格式化日期字符串 DecimalFormat nf = new DecimalFormat("0.00");// 格式化数字 switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_STRING: System.out.println(i + "行" + j + " 列 is String type"); value = cell.getStringCellValue(); break; case XSSFCell.CELL_TYPE_NUMERIC: System.out.println(i + "行" + j + " 列 is Number type ; DateFormt:" + cell.getCellStyle().getDataFormatString()); if ("@".equals(cell.getCellStyle().getDataFormatString())) { value = df.format(cell.getNumericCellValue()); } else if ("General".equals(cell.getCellStyle() .getDataFormatString())) { value = nf.format(cell.getNumericCellValue()); } else { value = sdf.format(HSSFDateUtil.getJavaDate(cell .getNumericCellValue())); } break; case XSSFCell.CELL_TYPE_BOOLEAN: System.out.println(i + "行" + j + " 列 is Boolean type"); value = cell.getBooleanCellValue(); break; case XSSFCell.CELL_TYPE_BLANK: System.out.println(i + "行" + j + " 列 is Blank type"); value = ""; break; default: System.out.println(i + "行" + j + " 列 is default type"); value = cell.toString(); } if (value == null || "".equals(value)) { continue; } linked.add(value); } list.add(linked); } return list; }