本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFCell.getBooleanCellValue方法的典型用法代码示例。如果您正苦于以下问题:Java HSSFCell.getBooleanCellValue方法的具体用法?Java HSSFCell.getBooleanCellValue怎么用?Java HSSFCell.getBooleanCellValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.hssf.usermodel.HSSFCell
的用法示例。
在下文中一共展示了HSSFCell.getBooleanCellValue方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBooleanCellValue
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public static boolean getBooleanCellValue(final HSSFSheet sheet, final int r, final int c) {
final HSSFRow row = sheet.getRow(r);
if (row == null) {
return false;
}
final HSSFCell cell = row.getCell(c);
if (cell == null) {
return false;
}
try {
return cell.getBooleanCellValue();
} catch (final RuntimeException e) {
System.err.println("Exception at sheet name:" + sheet.getSheetName() + ", row:" + (r + 1) + ", col:" + (c + 1));
throw e;
}
}
示例2: getBooleanCellValue
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public static boolean getBooleanCellValue(HSSFSheet sheet, int r, int c) {
HSSFRow row = sheet.getRow(r);
if (row == null) {
return false;
}
HSSFCell cell = row.getCell(c);
if (cell == null) {
return false;
}
try {
return cell.getBooleanCellValue();
} catch (RuntimeException e) {
System.err.println("Exception at sheet name:"
+ sheet.getSheetName() + ", row:" + (r + 1) + ", col:"
+ (c + 1));
throw e;
}
}
示例3: getStringValueOfCell
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private String getStringValueOfCell(HSSFCell cell, int cellType) {
switch (cellType) {
case Cell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue() ? "Ja" : "Nein";
case Cell.CELL_TYPE_FORMULA:
return getStringValueOfCell(cell, cell.getCachedFormulaResultType());
case Cell.CELL_TYPE_NUMERIC:
double number = cell.getNumericCellValue();
if(Double.isInfinite(number) || Double.isNaN(number) || Math.floor(number) != number)
return Double.toString(number);
else
return String.valueOf(new Double(number).intValue());
case Cell.CELL_TYPE_STRING:
return cell.getStringCellValue();
}
AtomTools.log(Level.SEVERE, "unknown celltype: " + cellType + "; content of cell = " + cell.toString(), this);
return null;
}
示例4: manageBoolean
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private Boolean manageBoolean(PreparedStatement ps, PreparedStatement psUpdate, int lfdCol, HSSFCell cell) throws SQLException {
Boolean result = null;
if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
if (ps != null) ps.setNull(lfdCol, java.sql.Types.BOOLEAN);
if (psUpdate != null) psUpdate.setNull(lfdCol, java.sql.Types.BOOLEAN);
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
result = cell.getNumericCellValue() != 0;
if (ps != null) ps.setBoolean(lfdCol, result);
if (psUpdate != null) psUpdate.setBoolean(lfdCol, result);
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
result = cell.getStringCellValue().equalsIgnoreCase("true");
if (ps != null) ps.setBoolean(lfdCol, result);
if (psUpdate != null) psUpdate.setBoolean(lfdCol, result);
} else {
result = cell.getBooleanCellValue();
if (ps != null) ps.setBoolean(lfdCol, result);
if (psUpdate != null) psUpdate.setBoolean(lfdCol, result);
}
//ps.setNull(lfdCol, java.sql.Types.BOOLEAN);
return result;
}
示例5: getValueFromCell
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
/**
* <b>描述:</b> 从单元格中获取到的数据
* @param cell 单元格对应的HSSFCell对象
* @return Object 从单元格中获取到的数据
*/
private Object getValueFromCell(HSSFCell cell){
if(cell==null)return "";
switch(cell.getCellType()){
case HSSFCell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue();
case HSSFCell.CELL_TYPE_NUMERIC:
return cell.getNumericCellValue();
case HSSFCell.CELL_TYPE_FORMULA:
return cell.getCellFormula();
case HSSFCell.CELL_TYPE_STRING:
return cell.getRichStringCellValue().toString();
default:
return cell.getRichStringCellValue().toString();
}
}
示例6: getCellString
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private Object getCellString(HSSFCell cell) {
// TODO Auto-generated method stub
Object result = null;
if (cell != null) {
// 单元格类型:Numeric:0,String:1,Formula:2,Blank:3,Boolean:4,Error:5
int cellType = cell.getCellType();
switch (cellType) {
case HSSFCell.CELL_TYPE_STRING:
result = cell.getRichStringCellValue().getString();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
result = cell.getNumericCellValue();
break;
case HSSFCell.CELL_TYPE_FORMULA:
result = cell.getNumericCellValue();
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
result = cell.getBooleanCellValue();
break;
case HSSFCell.CELL_TYPE_BLANK:
result = null;
break;
case HSSFCell.CELL_TYPE_ERROR:
result = null;
break;
default:
System.out.println("枚举了所有类型");
break;
}
}
return result;
}
示例7: getHSSFCellValue
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public String getHSSFCellValue(HSSFCell cell) {
String value = "";
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_NUMERIC:
if (HSSFDateUtil.isCellDateFormatted(cell)) {
value = HSSFDateUtil.getJavaDate(cell.getNumericCellValue())
.toString();
} else {
value = String.valueOf(cell.getNumericCellValue());
}
break;
case HSSFCell.CELL_TYPE_STRING:
value = cell.getRichStringCellValue().toString();
break;
case HSSFCell.CELL_TYPE_FORMULA:
value = String.valueOf(cell.getNumericCellValue());
if (value.equals("NaN")) {
value = cell.getRichStringCellValue().toString();
}
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
value = "" + cell.getBooleanCellValue();
break;
case HSSFCell.CELL_TYPE_BLANK:
value = "";
break;
case HSSFCell.CELL_TYPE_ERROR:
value = "";
break;
default:
value = cell.getRichStringCellValue().toString();
}
return value;
}
示例8: getDoubleValueOfCell
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private Double getDoubleValueOfCell(HSSFCell cell, int cellType) {
switch (cellType) {
case Cell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue() ? new Double(1) : new Double(0);
case Cell.CELL_TYPE_FORMULA:
return getDoubleValueOfCell(cell, cell.getCachedFormulaResultType());
case Cell.CELL_TYPE_NUMERIC:
// TO DO apply the dataformat for this cell
// if (HSSFDateUtil.isCellDateFormatted(cell)) {
// DateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
// return sdf.format(cell.getDateCellValue());
// }
return cell.getNumericCellValue();
// return value.intValue();
case Cell.CELL_TYPE_STRING:
return Double.parseDouble(cell.getStringCellValue());
default:
AtomTools.log(Level.SEVERE, "unknown celltype: " + cellType + "; content of cell = " + cell.toString(), this);
return null;
}
}
示例9: getValue
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public Object getValue(int row, String column) throws DataSetException {
if (logger.isDebugEnabled())
logger.debug("getValue(row={}, columnName={}) - start", Integer.toString(row), column);
assertValidRowIndex(row);
int columnIndex = getColumnIndex(column);
HSSFCell cell = _sheet.getRow(row + 1).getCell(columnIndex);
if (cell == null) {
return null;
}
int type = cell.getCellType();
switch (type) {
case HSSFCell.CELL_TYPE_NUMERIC:
HSSFCellStyle style = cell.getCellStyle();
if (HSSFDateUtil.isCellDateFormatted(cell)) {
return getDateValue(cell);
} else if (XlsDataSetWriter.DATE_FORMAT_AS_NUMBER_DBUNIT.equals(style.getDataFormatString())) {
// The special dbunit date format
return getDateValueFromJavaNumber(cell);
} else {
return getNumericValue(cell);
}
case HSSFCell.CELL_TYPE_STRING:
return cell.getRichStringCellValue().getString();
case HSSFCell.CELL_TYPE_FORMULA:
throw new DataTypeException("Formula not supported at row=" +
row + ", column=" + column);
case HSSFCell.CELL_TYPE_BLANK:
return null;
case HSSFCell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue() ? Boolean.TRUE : Boolean.FALSE;
case HSSFCell.CELL_TYPE_ERROR:
throw new DataTypeException("Error at row=" + row +
", column=" + column);
default:
throw new DataTypeException("Unsupported type at row=" + row +
", column=" + column);
}
}
示例10: getCellValue
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
/**
* This is a helper method to retrieve the value of a
* cell regardles of its type, which will be converted
* into a String.
*
* @param cell
* @return
*/
private String getCellValue(HSSFCell cell) {
if (cell == null) {
return null;
}
String result = null;
int cellType = cell.getCellType();
switch (cellType) {
case HSSFCell.CELL_TYPE_BLANK:
result = "";
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
result = cell.getBooleanCellValue() ?
"true" : "false";
break;
case HSSFCell.CELL_TYPE_ERROR:
result = "ERROR: " + cell.getErrorCellValue();
break;
case HSSFCell.CELL_TYPE_FORMULA:
result = cell.getCellFormula();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
HSSFCellStyle cellStyle = cell.getCellStyle();
short dataFormat = cellStyle.getDataFormat();
// assumption is made that dataFormat = 15,
// when cellType is HSSFCell.CELL_TYPE_NUMERIC
// is equal to a DATE format.
if (dataFormat == 15) {
result = cell.getDateCellValue().toString();
} else {
result = String.valueOf(
cell.getNumericCellValue());
}
break;
case HSSFCell.CELL_TYPE_STRING:
result = cell.getStringCellValue();
break;
default:
break;
}
return result;
}
示例11: getBooleanValueOfCell
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private Boolean getBooleanValueOfCell(HSSFCell cell, int cellType) {
switch (cellType) {
case Cell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue();
case Cell.CELL_TYPE_FORMULA:
return getBooleanValueOfCell(cell, cell.getCachedFormulaResultType());
case Cell.CELL_TYPE_NUMERIC:
return cell.getNumericCellValue() <= 0 ? false : true;
case Cell.CELL_TYPE_STRING:
String v = cell.getStringCellValue();
if(v == null || v.length() <= 0)
return null;
v = v.toLowerCase(Locale.GERMAN);
if(v.contains("k.a.") || v.contains("n.a."))
return null;
return (v.toLowerCase().contains("yes") || v.toLowerCase().contains("true") || v.toLowerCase().contains("ja") || v.contains("wahr") || v.equals("1"));
}
AtomTools.log(Level.SEVERE, "unknown celltype: " + cellType + "; content of cell = " + cell.toString(), this);
return null;
}