本文整理汇总了Java中org.apache.poi.xssf.usermodel.XSSFCell.getBooleanCellValue方法的典型用法代码示例。如果您正苦于以下问题:Java XSSFCell.getBooleanCellValue方法的具体用法?Java XSSFCell.getBooleanCellValue怎么用?Java XSSFCell.getBooleanCellValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.xssf.usermodel.XSSFCell
的用法示例。
在下文中一共展示了XSSFCell.getBooleanCellValue方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
public Object get(XSSFCell cell) {
if (cell != null) {
int cellType = cell.getCellType();
switch (cellType) {
case Cell.CELL_TYPE_NUMERIC:
return cell.getNumericCellValue();
case Cell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue();
default:
try {
return cell.getStringCellValue();
} catch (IllegalStateException mismatch) {
return null;
}
}
} else {
return null;
}
}
示例2: getStrCellVal
import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
/**
* 获取单元格字符串值
*
* @param cell
* @return
*
*/
public static String getStrCellVal(XSSFCell cell) {
if (cell == null) {
// 如果参数对象为空,
// 则直接退出!
return null;
}
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_STRING:
return cell.getStringCellValue();
case XSSFCell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue() ? "true" : "false";
default:
// 抛出异常
throw new XlsxTmplError(MessageFormat.format(
ERR_CELL_TYPE,
getSheetIndex(cell) + 1,
getSheetName(cell),
String.valueOf(cell.getRowIndex() + 1),
getColName(cell.getColumnIndex()),
String.class.getName(),
getCellTypeName(cell)
));
}
}
示例3: getCellDataAsString
import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
private String getCellDataAsString(XSSFCell cell) {
String value = "";
if (cell != null) {
int cellType = cell.getCellType();
switch (cellType) {
case Cell.CELL_TYPE_BLANK:
value = "";
break;
case Cell.CELL_TYPE_BOOLEAN:
value = (cell.getBooleanCellValue()) ? "true" : "false";
break;
case Cell.CELL_TYPE_ERROR:
value = cell.getErrorCellString();
break;
case Cell.CELL_TYPE_FORMULA:
value = cell.getStringCellValue();
break;
case Cell.CELL_TYPE_NUMERIC:
value = Double.toString(cell.getNumericCellValue());
break;
case Cell.CELL_TYPE_STRING:
default:
value = cell.getStringCellValue();
}
}
return value.trim();
}
示例4: getIntCellVal
import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
/**
* 获取单元格整数值
*
* @param cell
* @return
*
*/
public static Integer getIntCellVal(XSSFCell cell) {
if (cell == null) {
// 如果参数对象为空,
// 则直接退出!
return null;
}
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_NUMERIC:
return (int)cell.getNumericCellValue();
case XSSFCell.CELL_TYPE_STRING:
try {
return Integer.parseInt(cell.getStringCellValue());
} catch (Exception ex) {
// 抛出异常
throw new XlsxTmplError(MessageFormat.format(
BAD_CELL_FORMAT,
getSheetIndex(cell) + 1,
getSheetName(cell),
String.valueOf(cell.getRowIndex() + 1),
getColName(cell.getColumnIndex()),
ex.getMessage()
), ex);
}
case XSSFCell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue() ? 1 : 0;
default:
// 抛出异常
throw new XlsxTmplError(MessageFormat.format(
ERR_CELL_TYPE,
getSheetIndex(cell) + 1,
getSheetName(cell),
String.valueOf(cell.getRowIndex() + 1),
getColName(cell.getColumnIndex()),
Integer.class.getName(),
getCellTypeName(cell)
));
}
}
示例5: getLongCellVal
import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
/**
* 获取单元格长整数值
*
* @param cell
* @return
*
*/
public static Long getLongCellVal(XSSFCell cell) {
if (cell == null) {
// 如果参数对象为空,
// 则直接退出!
return null;
}
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_NUMERIC:
return (long)cell.getNumericCellValue();
case XSSFCell.CELL_TYPE_STRING:
try {
return Long.parseLong(cell.getStringCellValue());
} catch (Exception ex) {
// 抛出异常
throw new XlsxTmplError(MessageFormat.format(
BAD_CELL_FORMAT,
getSheetIndex(cell) + 1,
getSheetName(cell),
String.valueOf(cell.getRowIndex() + 1),
getColName(cell.getColumnIndex()),
ex.getMessage()
), ex);
}
case XSSFCell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue() ? 1L : 0L;
default:
// 抛出异常
throw new XlsxTmplError(MessageFormat.format(
ERR_CELL_TYPE,
getSheetIndex(cell) + 1,
getSheetName(cell),
String.valueOf(cell.getRowIndex() + 1),
getColName(cell.getColumnIndex()),
Long.class.getName(),
getCellTypeName(cell)
));
}
}
示例6: getShortCellVal
import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
/**
* 获取单元格短整数值
*
* @param cell
* @return
*
*/
public static Short getShortCellVal(XSSFCell cell) {
if (cell == null) {
// 如果参数对象为空,
// 则直接退出!
return null;
}
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_NUMERIC:
return (short)cell.getNumericCellValue();
case XSSFCell.CELL_TYPE_STRING:
try {
return Short.parseShort(cell.getStringCellValue());
} catch (Exception ex) {
// 抛出异常
throw new XlsxTmplError(MessageFormat.format(
BAD_CELL_FORMAT,
getSheetIndex(cell) + 1,
getSheetName(cell),
String.valueOf(cell.getRowIndex() + 1),
getColName(cell.getColumnIndex()),
ex.getMessage()
), ex);
}
case XSSFCell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue() ? (short)1 : (short)0;
default:
// 抛出异常
throw new XlsxTmplError(MessageFormat.format(
ERR_CELL_TYPE,
getSheetIndex(cell) + 1,
getSheetName(cell),
String.valueOf(cell.getRowIndex() + 1),
getColName(cell.getColumnIndex()),
Short.class.getName(),
getCellTypeName(cell)
));
}
}
示例7: getFloatCellVal
import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
/**
* 获取单元格单精度数值
*
* @param cell
* @return
*
*/
public static Float getFloatCellVal(XSSFCell cell) {
if (cell == null) {
// 如果参数对象为空,
// 则直接退出!
return null;
}
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_NUMERIC:
return (float)cell.getNumericCellValue();
case XSSFCell.CELL_TYPE_STRING:
try {
return Float.parseFloat(cell.getStringCellValue());
} catch (Exception ex) {
// 抛出异常
throw new XlsxTmplError(MessageFormat.format(
BAD_CELL_FORMAT,
getSheetIndex(cell) + 1,
getSheetName(cell),
String.valueOf(cell.getRowIndex() + 1),
getColName(cell.getColumnIndex()),
ex.getMessage()
), ex);
}
case XSSFCell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue() ? 1.0f : 0.0f;
default:
// 抛出异常
throw new XlsxTmplError(MessageFormat.format(
ERR_CELL_TYPE,
getSheetIndex(cell) + 1,
getSheetName(cell),
String.valueOf(cell.getRowIndex() + 1),
getColName(cell.getColumnIndex()),
Float.class.getName(),
getCellTypeName(cell)
));
}
}
示例8: getDoubleCellVal
import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
/**
* 获取单元格双精度数值
*
* @param cell
* @return
*
*/
public static Double getDoubleCellVal(XSSFCell cell) {
if (cell == null) {
// 如果参数对象为空,
// 则直接退出!
return null;
}
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_NUMERIC:
return (double)cell.getNumericCellValue();
case XSSFCell.CELL_TYPE_STRING:
try {
return Double.parseDouble(cell.getStringCellValue());
} catch (Exception ex) {
// 抛出异常
throw new XlsxTmplError(MessageFormat.format(
BAD_CELL_FORMAT,
getSheetIndex(cell) + 1,
getSheetName(cell),
String.valueOf(cell.getRowIndex() + 1),
getColName(cell.getColumnIndex()),
ex.getMessage()
), ex);
}
case XSSFCell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue() ? 1.0 : 0.0;
default:
// 抛出异常
throw new XlsxTmplError(MessageFormat.format(
ERR_CELL_TYPE,
getSheetIndex(cell) + 1,
getSheetName(cell),
String.valueOf(cell.getRowIndex() + 1),
getColName(cell.getColumnIndex()),
Double.class.getName(),
getCellTypeName(cell)
));
}
}
示例9: getBoolCellVal
import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
/**
* 获取单元格布尔值
*
* @param cell
* @return
*
*/
public static Boolean getBoolCellVal(XSSFCell cell) {
if (cell == null) {
// 如果参数对象为空,
// 则直接退出!
return false;
}
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_NUMERIC:
return (int)cell.getNumericCellValue() == 1;
case XSSFCell.CELL_TYPE_STRING:
// 获取单元格字符串值
final String cellVal = cell.getStringCellValue().toUpperCase();
return "1".equals(cellVal) ||
"TRUE".equals(cellVal) ||
"T".equals(cellVal) ||
"YES".equals(cellVal) ||
"Y".equals(cellVal);
case XSSFCell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue();
default:
// 抛出异常
throw new XlsxTmplError(MessageFormat.format(
ERR_CELL_TYPE,
getSheetIndex(cell) + 1,
getSheetName(cell),
String.valueOf(cell.getRowIndex() + 1),
getColName(cell.getColumnIndex()),
Boolean.class.getName(),
getCellTypeName(cell)
));
}
}
示例10: cellToString
import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
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();
}
示例11: compareTwoCells
import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
public static boolean compareTwoCells(XSSFCell cell1, XSSFCell cell2) {
if ((cell1 == null) && (cell2 == null)) {
return true;
} else if ((cell1 == null) || (cell2 == null)) {
return false;
}
boolean equalCells = false;
int type1 = cell1.getCellTypeEnum().getCode();
int type2 = cell2.getCellTypeEnum().getCode();
if (type1 == type2) {
if (cell1.getCellStyle().equals(cell2.getCellStyle())) {
// Compare cells based on its type
switch (cell1.getCellTypeEnum().getCode()) {
case HSSFCell.CELL_TYPE_FORMULA:
if (cell1.getCellFormula().equals(cell2.getCellFormula())) {
equalCells = true;
}
break;
case HSSFCell.CELL_TYPE_NUMERIC:
if (cell1.getNumericCellValue() == cell2.getNumericCellValue()) {
equalCells = true;
}
break;
case HSSFCell.CELL_TYPE_STRING:
if (cell1.getStringCellValue().equals(cell2.getStringCellValue())) {
equalCells = true;
}
break;
case HSSFCell.CELL_TYPE_BLANK:
if (cell2.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
equalCells = true;
}
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
if (cell1.getBooleanCellValue() == cell2.getBooleanCellValue()) {
equalCells = true;
}
break;
case HSSFCell.CELL_TYPE_ERROR:
if (cell1.getErrorCellValue() == cell2.getErrorCellValue()) {
equalCells = true;
}
break;
default:
if (cell1.getStringCellValue().equals(cell2.getStringCellValue())) {
equalCells = true;
}
break;
}
} else {
return false;
}
} else {
return false;
}
return equalCells;
}