当前位置: 首页>>代码示例>>Java>>正文


Java XSSFCell.getNumericCellValue方法代码示例

本文整理汇总了Java中org.apache.poi.xssf.usermodel.XSSFCell.getNumericCellValue方法的典型用法代码示例。如果您正苦于以下问题:Java XSSFCell.getNumericCellValue方法的具体用法?Java XSSFCell.getNumericCellValue怎么用?Java XSSFCell.getNumericCellValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.xssf.usermodel.XSSFCell的用法示例。


在下文中一共展示了XSSFCell.getNumericCellValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
    }

}
 
开发者ID:theysay,项目名称:preceive-batch,代码行数:21,代码来源:XLSXSourceProvider.java

示例2: getValue

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
public static Object getValue(XSSFSheet sheet, int row, int col) {
    try {

        XSSFRow xrow = sheet.getRow(row);
        XSSFCell cell = xrow.getCell(col);

        switch (cell.getCellType()) {
            case Cell.CELL_TYPE_NUMERIC:
                return cell.getNumericCellValue();
            case Cell.CELL_TYPE_STRING:
                return (new DateComponentFormatter(
                        ComponentManager.getInstance().getComponentFormatDefaults().getSelectedDateFormat()))
                        .stringToValue(cell.getStringCellValue());
        }

    } catch (ParseException e) {
        e.printStackTrace();
    }

    return null;
}
 
开发者ID:pghazal,项目名称:NoMoreLine,代码行数:22,代码来源:ExcelUtils.java

示例3: fromXSSFRowtoCSV

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
private String fromXSSFRowtoCSV(XSSFRow row){
    StringBuffer csvRow = new StringBuffer();
    int l = row.getLastCellNum();
    for (int i=0;i<l;i++){
        XSSFCell cell = row.getCell((short)i);
        String cellValue = "";
        if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
            cellValue = "";
        } else if (cell.getCellType()== HSSFCell.CELL_TYPE_STRING){
            cellValue = "\"" + cell.getStringCellValue() + "\"";
        } else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
            double value = cell.getNumericCellValue();
            cellValue = getNumberFormat().format(value);
            cellValue = "\"" + cellValue + "\"";
        }

        csvRow.append(cellValue);

        if (i<l){
            csvRow.append(getCsvDelimiter().toCharArray()[0]);
        }
    }
    return csvRow.toString();
}
 
开发者ID:sakaiproject,项目名称:sakai,代码行数:25,代码来源:SpreadsheetUploadBean.java

示例4: validate

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
@Override
public ValidationResult validate(XSSFCell cell) {
	int cellType = cell.getCellType();
	if (cellType == Cell.CELL_TYPE_BLANK) {
		return null;
	}

	double cellValue;
	if (cellType == Cell.CELL_TYPE_NUMERIC) {
		cellValue = cell.getNumericCellValue();
	} else if (cellType == Cell.CELL_TYPE_STRING) {
		 String stringValue = cell.getStringCellValue();
		 try{
			 cellValue = Double.parseDouble(stringValue);
			 //Warning 
		 }catch(NumberFormatException e){
			 //Error
			 return new ValidationResultImpl(cell.getSheet().getSheetName(), cell.getReference(),  false, "Value type is not as expected!");
		 }
	} else {
		return new ValidationResultImpl(cell.getSheet().getSheetName(), cell.getReference(), false, "Value type is not as expected!"); //Error
	}
	
	if (operator.check(cellValue)) {
		//True
		return null;
	} else {
		//Error
		return new ValidationResultImpl(cell.getSheet().getSheetName(), cell.getReference(), false, "Error!");
	}
}
 
开发者ID:ykaragol,项目名称:poi-data-validation,代码行数:32,代码来源:DecimalValidator.java

示例5: getSingleValue

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
private Double getSingleValue(XSSFSheet sheet, String formula) {
	try {
		return Double.parseDouble(formula);
	} catch (NumberFormatException e) {
		CellReference cellReference = new CellReference(formula);
		if (cellReference.getSheetName() != null) {
			sheet = sheet.getWorkbook().getSheet(cellReference.getSheetName());
		}
		XSSFRow row = sheet.getRow(cellReference.getRow());
		XSSFCell cell = row.getCell(cellReference.getCol());
		return cell.getNumericCellValue();
	}
}
 
开发者ID:ykaragol,项目名称:poi-data-validation,代码行数:14,代码来源:DataValidator.java

示例6: 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)
        ));
    }
}
 
开发者ID:hjj2017,项目名称:xgame-code_server,代码行数:47,代码来源:XSSFUtil.java

示例7: 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)
        ));
    }
}
 
开发者ID:hjj2017,项目名称:xgame-code_server,代码行数:47,代码来源:XSSFUtil.java

示例8: 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)
        ));
    }
}
 
开发者ID:hjj2017,项目名称:xgame-code_server,代码行数:47,代码来源:XSSFUtil.java

示例9: 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)
        ));
    }
}
 
开发者ID:hjj2017,项目名称:xgame-code_server,代码行数:47,代码来源:XSSFUtil.java

示例10: 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)
        ));
    }
}
 
开发者ID:hjj2017,项目名称:xgame-code_server,代码行数:47,代码来源:XSSFUtil.java

示例11: 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)
        ));
    }
}
 
开发者ID:hjj2017,项目名称:xgame-code_server,代码行数:41,代码来源:XSSFUtil.java

示例12: 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();
	}
 
开发者ID:Madusudanan,项目名称:Selenium,代码行数:28,代码来源:readExcelXLSX.java

示例13: readTypeNumeric

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
@Override
public String readTypeNumeric(XSSFCell cell) {
	return cell.getNumericCellValue() + "";
}
 
开发者ID:lucastanziano,项目名称:JavaFX-Skeleton-DEPRECATED,代码行数:5,代码来源:BaseCellReader.java

示例14: validate

import org.apache.poi.xssf.usermodel.XSSFCell; //导入方法依赖的package包/类
@Override
public ValidationResult validate(XSSFCell cell) {
	//result ??
	int cellType = cell.getCellType();
	if (cellType == Cell.CELL_TYPE_BLANK) {
		return null;
	}
	
	double cellValue;
	if (cellType == Cell.CELL_TYPE_NUMERIC) {
		cellValue = cell.getNumericCellValue();
	} else if (cellType == Cell.CELL_TYPE_STRING) {
		 String stringValue = cell.getStringCellValue();
		 try{
			 cellValue = Double.parseDouble(stringValue);
			 //Warning 
		 }catch(NumberFormatException e){
			 //Error
			 return new ValidationResultImpl(cell.getSheet().getSheetName(), cell.getReference(), false, "Error!");
		 }
	} else {
		//Error
		return new ValidationResultImpl(cell.getSheet().getSheetName(), cell.getReference(), false, "Error!");
	}
	//TODO : refactor above code, they are duplicate with DecimalValidator!
	
	int intRepresentation = (int) cellValue;
	if(Double.compare(cellValue, intRepresentation)==0){
		//Continue...
	}else{
		//Error
		return new ValidationResultImpl(cell.getSheet().getSheetName(), cell.getReference(), false, "Error!");
	}
	
	if (operator.check(cellValue)) {
		//True
	} else {
		return new ValidationResultImpl(cell.getSheet().getSheetName(), cell.getReference(), false, "Error!");
		//Error
	}
	return null;
}
 
开发者ID:ykaragol,项目名称:poi-data-validation,代码行数:43,代码来源:NumericValidator.java

示例15: 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;
}
 
开发者ID:Talend,项目名称:data-prep,代码行数:59,代码来源:ExcelComparator.java


注:本文中的org.apache.poi.xssf.usermodel.XSSFCell.getNumericCellValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。