當前位置: 首頁>>代碼示例>>Java>>正文


Java Cell.getNumericCellValue方法代碼示例

本文整理匯總了Java中org.apache.poi.ss.usermodel.Cell.getNumericCellValue方法的典型用法代碼示例。如果您正苦於以下問題:Java Cell.getNumericCellValue方法的具體用法?Java Cell.getNumericCellValue怎麽用?Java Cell.getNumericCellValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.poi.ss.usermodel.Cell的用法示例。


在下文中一共展示了Cell.getNumericCellValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCharValue

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
private char getCharValue(Cell cell) {
	int vType = getCellType(cell);
	switch (vType) {
	case Cell.CELL_TYPE_BLANK:
		return 0;
	case Cell.CELL_TYPE_NUMERIC:
		return (char) cell.getNumericCellValue();
	case Cell.CELL_TYPE_STRING:
		String vStr = cell.getStringCellValue();
		if (vStr.length() == 1)
			return vStr.charAt(0);
		else
			throw new IllegalArgumentException("Can't get char from String whose length > 1");
	default:
		throw new IllegalArgumentException("Can't get char from type " + vType);
	}
}
 
開發者ID:xinufo,項目名稱:teemo,代碼行數:18,代碼來源:RowExcelImpl.java

示例2: getNumbericValue

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
private double getNumbericValue(Cell cell, Class<? extends Number> clazz) {
	double vRet;
	int vType = getCellType(cell);
	switch (vType) {
	case Cell.CELL_TYPE_BLANK:
		vRet = 0;
		break;
	case Cell.CELL_TYPE_NUMERIC:
		vRet = cell.getNumericCellValue();
		break;
	case Cell.CELL_TYPE_STRING:
		String vStr = cell.getStringCellValue();
		vRet = Double.valueOf(vStr);
		break;
	default:
		throw new IllegalArgumentException("Can't get " + clazz.getSimpleName() + " from type " + vType);
	}
	return vRet;
}
 
開發者ID:xinufo,項目名稱:teemo,代碼行數:20,代碼來源:RowExcelImpl.java

示例3: getStringValue

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
private String getStringValue(Cell cell) {
	int vType = getCellType(cell);
	switch (vType) {
	case Cell.CELL_TYPE_STRING:
		return cell.getStringCellValue();
	case Cell.CELL_TYPE_BOOLEAN:
		return String.valueOf(cell.getBooleanCellValue());
	case Cell.CELL_TYPE_NUMERIC:
		double vValue = cell.getNumericCellValue();
		if (doubleIsInt(vValue))
			return String.valueOf((int) vValue);
		return String.valueOf(vValue);
	case Cell.CELL_TYPE_BLANK:
		return "";
	default:
		throw new IllegalArgumentException("Can't get String from type " + vType);
	}
}
 
開發者ID:xinufo,項目名稱:teemo,代碼行數:19,代碼來源:RowExcelImpl.java

示例4: getStartRow

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
private int getStartRow(Sheet sheet) throws SheetParsingException {

		Iterator<Row> rit = sheet.iterator();
		while (rit.hasNext()) {
			Row row = rit.next();
			Cell cell = row.getCell(0);

			if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
				/*
				 * In my case first column is Sr.no. and Data starts where sr. no is 1 ,so this
				 * is start row index
				 */
				if (cell.getNumericCellValue() == 1.0)
					return row.getRowNum();
			}
		}
		throw new SheetParsingException("no start index found for data");
	}
 
開發者ID:NeebalLearningPvtLtd,項目名稱:Excel-to-POJO,代碼行數:19,代碼來源:SheetParser.java

示例5: geByte

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
public static Byte geByte(Cell cell) {
    if (isNullCell(cell)) {
        return null;
    }
    if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
        return (byte) cell.getNumericCellValue();
    }
    if (Cell.CELL_TYPE_STRING == cell.getCellType()) {
        String value = cell.getStringCellValue();
        if(StringUtils.isNotEmpty(value)){
            Byte.valueOf(cell.getStringCellValue());
        }else{
            return null;
        }
    }
    throw new RuntimeException("can not convertWithConstructor cell value to Integer!");
}
 
開發者ID:dengxiangjun,項目名稱:OfficeAutomation,代碼行數:18,代碼來源:CellConvert.java

示例6: 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;
}
 
開發者ID:long47964,項目名稱:excel-utils,代碼行數:46,代碼來源:ExcelImportUtil.java

示例7: 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;
}
 
開發者ID:sombie007,項目名稱:ExcelHandle,代碼行數:42,代碼來源:ImportExcel.java

示例8: 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;
}
 
開發者ID:NeebalLearningPvtLtd,項目名稱:Excel-to-POJO,代碼行數:35,代碼來源:RowParser.java

示例9: getInteger

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
public static Integer getInteger(Cell cell) {
    if (isNullCell(cell)) {
        return null;
    }
    if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
        return (int) cell.getNumericCellValue();
    }
    if (Cell.CELL_TYPE_STRING == cell.getCellType()) {
        return Integer.parseInt(cell.getStringCellValue());
    }
    throw new RuntimeException("can not convertWithConstructor cell value to Integer!");
}
 
開發者ID:dengxiangjun,項目名稱:OfficeAutomation,代碼行數:13,代碼來源:CellConvert.java

示例10: getFloat

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
public static Float getFloat(Cell cell) {
    if (isNullCell(cell)) {
        return null;
    }
    if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
        return (float) cell.getNumericCellValue();
    }
    if (Cell.CELL_TYPE_STRING == cell.getCellType()) {
        return Float.parseFloat(cell.getStringCellValue());
    }
    throw new RuntimeException("can not convertWithConstructor cell value to Float!");
}
 
開發者ID:dengxiangjun,項目名稱:OfficeAutomation,代碼行數:13,代碼來源:CellConvert.java

示例11: getDouble

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
public static Double getDouble(Cell cell) {
    if (isNullCell(cell)) {
        return null;
    }
    if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
        return cell.getNumericCellValue();
    }
    if (Cell.CELL_TYPE_STRING == cell.getCellType()) {
        return Double.parseDouble(cell.getStringCellValue());
    }
    throw new RuntimeException("can not convertWithConstructor cell value to Double!");
}
 
開發者ID:dengxiangjun,項目名稱:OfficeAutomation,代碼行數:13,代碼來源:CellConvert.java

示例12: getShort

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
public static Short getShort(Cell cell) {
    if (isNullCell(cell)) {
        return null;
    }
    if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
        return (short) cell.getNumericCellValue();
    }
    if (Cell.CELL_TYPE_STRING == cell.getCellType()) {
        return Short.parseShort(cell.getStringCellValue());
    }
    throw new RuntimeException("can not convertWithConstructor cell value to Short!");
}
 
開發者ID:dengxiangjun,項目名稱:OfficeAutomation,代碼行數:13,代碼來源:CellConvert.java

示例13: getLong

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
public static Long getLong(Cell cell) {
    if (isNullCell(cell)) {
        return null;
    }
    if (Cell.CELL_TYPE_NUMERIC == cell.getCellType()) {
        return (long) cell.getNumericCellValue();
    }
    if (Cell.CELL_TYPE_STRING == cell.getCellType()) {
        return Longs.tryParse(cell.getStringCellValue());
    }
    throw new RuntimeException("can not convertWithConstructor cell value to Long!");
}
 
開發者ID:dengxiangjun,項目名稱:OfficeAutomation,代碼行數:13,代碼來源:CellConvert.java

示例14: doubleValue

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
/**
 * 獲取 cell 的值
 *
 * @param cell
 * @return  返回 double 值,獲取失敗返回{@link #CELL_VALUE_ERROR}
 */
public static double doubleValue(Cell cell){
    try {
        return cell.getNumericCellValue();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return CELL_VALUE_ERROR;
}
 
開發者ID:linchaolong,項目名稱:ExcelParser,代碼行數:15,代碼來源:ExcelUtils.java

示例15: read

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
private List<List<String>> read(Workbook wb, int sheetIndex) {
    List<List<String>> dataLst = Lists.newArrayList();
    Sheet sheet = wb.getSheetAt(sheetIndex);
    this.totalRows = sheet.getPhysicalNumberOfRows();
    if ((this.totalRows >= 1) && (sheet.getRow(0) != null)) {
        this.totalCells = sheet.getRow(0).getLastCellNum(); // 獲取最後一個不為空的列是第幾個
    }
    for (int r = 0; r < this.totalRows; r++) {
        Row row = sheet.getRow(r);
        if (row != null) {
            List<String> rowLst = Lists.newArrayList();
            for (int c = 0; c < getTotalCells(); c++) {
                Cell cell = row.getCell(c);

                String cellValue = "";
                if (cell != null) {
                    switch (cell.getCellType()) {
                        case 0:
                            if (HSSFDateUtil.isCellDateFormatted(cell)) {
                                Date date = cell.getDateCellValue();

                                cellValue = DateUtils.dateToStr(date,
                                        "yyyy-MM-dd HH:mm:ss");

                            } else {
                                Integer num = (int) cell.getNumericCellValue();
                                cellValue = String.valueOf(num);
                            }
                            break;
                        case 1:
                            cellValue = cell.getStringCellValue().trim();
                            break;
                        case 4:
                            cellValue = String.valueOf(cell.getBooleanCellValue());
                            break;
                        case 2:
                            cellValue = cell.getCellFormula();
                            break;
                        case 3:
                            cellValue = "";
                            break;
                        case 5:
                            cellValue = "非法字符";
                            break;
                        default:
                            cellValue = "未知類型";
                    }
                }
                rowLst.add(cellValue);
            }
            dataLst.add(rowLst);
        }
    }
    return dataLst;
}
 
開發者ID:DreamYa0,項目名稱:zeratul,代碼行數:56,代碼來源:HandleExcel.java


注:本文中的org.apache.poi.ss.usermodel.Cell.getNumericCellValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。