本文整理匯總了Java中org.apache.poi.ss.usermodel.Cell.getBooleanCellValue方法的典型用法代碼示例。如果您正苦於以下問題:Java Cell.getBooleanCellValue方法的具體用法?Java Cell.getBooleanCellValue怎麽用?Java Cell.getBooleanCellValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.ss.usermodel.Cell
的用法示例。
在下文中一共展示了Cell.getBooleanCellValue方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getCellValue
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
public Object getCellValue(Cell cell){
Object value = null;
DecimalFormat df = new DecimalFormat("0"); //格式化number String字符
DecimalFormat df2 = new DecimalFormat("0.00"); //格式化數字
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
value = cell.getRichStringCellValue().getString();
break;
case Cell.CELL_TYPE_NUMERIC:
if("General".equals(cell.getCellStyle().getDataFormatString())) {
value = df.format(cell.getNumericCellValue());
} else {
value = df2.format(cell.getNumericCellValue());
}
break;
case Cell.CELL_TYPE_BOOLEAN:
value = cell.getBooleanCellValue();
break;
case Cell.CELL_TYPE_BLANK:
value = "";
break;
default:
break;
}
return value;
}
示例2: objectFrom
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
private Object objectFrom(final HSSFWorkbook workbook, final Cell cell) {
Object cellValue = null;
if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
cellValue = cell.getRichStringCellValue().getString();
} else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
cellValue = getNumericCellValue(cell);
} else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
cellValue = cell.getBooleanCellValue();
} else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
cellValue = evaluateCellFormula(workbook, cell);
}
return cellValue;
}
示例3: getValue
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
/** 從表格之中讀取數據並進行處理
* @param fieldInfo
* @param cell 當前cell
* @return
* @throws Exception
*/
public static Object getValue(ImportFieldInfo fieldInfo, Cell cell) throws Exception{
int size = fieldInfo.getTypeChain().size();
Class<?> type = fieldInfo.getTypeChain().get(size - 1);
String dateFormat = fieldInfo.getDateFormat();
int cellType = cell.getCellType();
Object obj = null ;
switch (cellType) {
case Cell.CELL_TYPE_BLANK:
return null;
case Cell.CELL_TYPE_BOOLEAN:
obj = cell.getBooleanCellValue();
break;
case Cell.CELL_TYPE_STRING:
obj = cell.getStringCellValue();
break;
case Cell.CELL_TYPE_NUMERIC:
if(DateUtil.isCellDateFormatted(cell)){
obj = DateUtil.getJavaDate(cell.getNumericCellValue());
}else if(Number.class.isAssignableFrom(type) || ClassUtils.isBaseNumberType(type)){
//當pojo字段類型是數字型時以數字形式獲取
obj = cell.getNumericCellValue();
}else{
//其他類型都以string獲取
obj = DATA_FORMATTER.formatCellValue(cell);
}
break;
case Cell.CELL_TYPE_ERROR:
return null;
}
if(fieldInfo.getImportProcessor() != null){
obj = fieldInfo.getImportProcessor().process(obj);
}
obj = ConvertUtils.convertIfNeccesary(obj, type, dateFormat);
return obj;
}
示例4: getCellValue
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
/**
* 獲取單元格值
*
* @param row 獲取的行
* @param column 獲取單元格列號
* @return 單元格值
*/
public Object getCellValue(Row row, int column) {
Object val = "";
try {
Cell cell = row.getCell(column);
if (cell != null) {
if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
// val = cell.getNumericCellValue();
// 當excel 中的數據為數值或日期是需要特殊處理
if (HSSFDateUtil.isCellDateFormatted(cell)) {
double d = cell.getNumericCellValue();
Date date = HSSFDateUtil.getJavaDate(d);
SimpleDateFormat dformat = new SimpleDateFormat(
"yyyy-MM-dd");
val = dformat.format(date);
} else {
NumberFormat nf = NumberFormat.getInstance();
nf.setGroupingUsed(false);// true時的格式:1,234,567,890
val = nf.format(cell.getNumericCellValue());// 數值類型的數據為double,所以需要轉換一下
}
} else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
val = cell.getStringCellValue();
} else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
val = cell.getCellFormula();
} else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
val = cell.getBooleanCellValue();
} else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) {
val = cell.getErrorCellValue();
}
}
} catch (Exception e) {
return val;
}
return val;
}
示例5: getBooleanValue
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
private boolean getBooleanValue(Cell cell) {
switch (getCellType(cell)) {
case Cell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue();
case Cell.CELL_TYPE_NUMERIC:
return Double.compare(cell.getNumericCellValue(), 0) != 0;
case Cell.CELL_TYPE_STRING:
return Boolean.valueOf(cell.getStringCellValue());
default:
return false;
}
}
示例6: getValue
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
private Object getValue(Cell raw, String fieldType) throws CellParsingException {
switch (raw.getCellType()) {
case Cell.CELL_TYPE_BOOLEAN:
return raw.getBooleanCellValue();
case Cell.CELL_TYPE_STRING: {
String s = raw.getStringCellValue();
String boolString = s.toLowerCase();
if (boolString.equals("yes"))
return true;
if (boolString.equals("no"))
return false;
return s;
}
case Cell.CELL_TYPE_NUMERIC:
if (DateUtil.isCellDateFormatted(raw)) {
Date date = raw.getDateCellValue();
return LocalDate.of(date.getYear() + 1900, date.getMonth() + 1, date.getDate());
}
return (int) raw.getNumericCellValue();
// formula parsing doesnot work
// can be done using FormulaEvaluater
case Cell.CELL_TYPE_FORMULA:
return true;
case Cell.CELL_TYPE_BLANK: {
return getInstance(fieldType);
}
}
return null;
}
示例7: getBoolean
import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
public static Boolean getBoolean(Cell cell) {
if (isNullCell(cell)) {
return null;
}
if (Cell.CELL_TYPE_BOOLEAN == cell.getCellType()) {
return cell.getBooleanCellValue();
}
if (Cell.CELL_TYPE_STRING == cell.getCellType()) {
String value = cell.getStringCellValue();
return "1".equals(value) || "是".equals(value);
}
throw new RuntimeException("can not convertWithConstructor cell value to Boolean!");
}