Java Code Examples for org.apache.poi.hssf.usermodel.HSSFCell#getBooleanCellValue()

The following examples show how to use org.apache.poi.hssf.usermodel.HSSFCell#getBooleanCellValue() . 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: POIUtils.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
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;
    }
}
 
Example 2
Source File: PoiUtil.java    From dk-fitting with Apache License 2.0 5 votes vote down vote up
/**
 * 获取单元格中的内容 ,该犯法用于解析各种形式的数据
 */
private Object getCellString(HSSFCell cell) {
    Object result = null;
    if (cell != null) {
        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_ERROR:
                result = null;
                break;
            case HSSFCell.CELL_TYPE_BOOLEAN:
                result = cell.getBooleanCellValue();
                break;
            case HSSFCell.CELL_TYPE_BLANK:
                result = null;
                break;
            default:
                break;
        }
    }
    return result;
}
 
Example 3
Source File: POIUtils.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
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;
	}
	
	return cell.getBooleanCellValue();
}
 
Example 4
Source File: readExcel.java    From Selenium with The Unlicense 5 votes vote down vote up
private static String cellToString(HSSFCell 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 5
Source File: XlsTable.java    From Leo with Apache License 2.0 4 votes vote down vote up
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);
    }
}