當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。