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


Java Cell.CELL_TYPE_FORMULA屬性代碼示例

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


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

示例1: getNativeValueType

@Override
public ValueType getNativeValueType(int columnIndex) throws ParseException {
	Cell cell = getCurrentCell(columnIndex);
	final int type = cell.getCellType();
	if (type == Cell.CELL_TYPE_BLANK) {
		return ValueType.EMPTY;
	} else if (type == Cell.CELL_TYPE_STRING) {
		return ValueType.STRING;
	} else if (type == Cell.CELL_TYPE_NUMERIC) {
		if (DateUtil.isCellDateFormatted(cell)) {
			return ValueType.DATE;
		} else {
			return ValueType.NUMBER;
		}
	} else if (type == Cell.CELL_TYPE_FORMULA) {
		if (cell.getCachedFormulaResultType() == Cell.CELL_TYPE_NUMERIC) {
			return ValueType.NUMBER;
		} else {
			return ValueType.STRING;
		}
	} else {
		return ValueType.STRING;
	}
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:24,代碼來源:Excel2007ResultSet.java

示例2: objectFrom

private Object objectFrom(final HSSFWorkbook workbook, final Cell cell) {
    Object cellValue = null;
    if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
        cellValue = cell.getRichStringCellValue().getString();
    } else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
        cellValue = getNumericCellValue(cell);
    } else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
        cellValue = cell.getBooleanCellValue();
    } else if (cell.getCellType()  == Cell.CELL_TYPE_FORMULA) {
        cellValue = evaluateCellFormula(workbook, cell);
    }
    return cellValue;

}
 
開發者ID:cyber-coders-j2017a,項目名稱:modern.core.java.repo,代碼行數:14,代碼來源:ExcelXlsReaderParameter.java

示例3: isBlankRow

/**
 * 判斷空行
 */
private static boolean isBlankRow(Row row) {
    if (row == null) {
        return true;
    }
    boolean result = true;
    Iterator<Cell> cells = row.cellIterator();
    String value = "";
    while (cells.hasNext()) {
        Cell cell = cells.next();
        int cellType = cell.getCellType();
        switch (cellType) {
            case Cell.CELL_TYPE_NUMERIC:
                value = String.valueOf(cell.getNumericCellValue());
                break;
            case Cell.CELL_TYPE_STRING:
                value = cell.getStringCellValue();
                break;
            case Cell.CELL_TYPE_BOOLEAN:
                value = String.valueOf(cell.getBooleanCellValue());
                break;
            case Cell.CELL_TYPE_FORMULA:
                value = String.valueOf(cell.getCellFormula());
                break;
        }
        if (StringUtils.isNotBlank(value)) {
            result = false;
            break;
        }
    }

    return result;
}
 
開發者ID:goribun,項目名稱:excel-rw-annotation,代碼行數:35,代碼來源:BaseReadUtil.java

示例4: intercepterCellValue

public void intercepterCellValue(Cell cell, CellWrapper cellWrapper, String interceptor) throws Exception {
	if (cell == null) {
		cellWrapper.setValue(null);
	} else {
		int cellType = cell.getCellType();
		switch (cellType) {
		case Cell.CELL_TYPE_BLANK:
			cellWrapper.setValue(null);
			break;
		case Cell.CELL_TYPE_BOOLEAN:
			cellWrapper.setValue(Boolean.valueOf(cell.getBooleanCellValue()));
			break;
		case Cell.CELL_TYPE_ERROR:
			cellWrapper.setValue(cell.getErrorCellValue());
			break;
		case Cell.CELL_TYPE_FORMULA:
			cellWrapper.setValue(cell.getCellFormula());
			break;
		case Cell.CELL_TYPE_NUMERIC:
			if (DateUtil.isCellDateFormatted(cell)) {
				Date date = cell.getDateCellValue();
				cellWrapper.setValue(date);
			} else {
				cellWrapper.setValue(cell.getNumericCellValue());
			}
			break;
		case Cell.CELL_TYPE_STRING:
			cellWrapper.setValue(cell.getStringCellValue());
			break;
		}
	}
	logger.debug("before interceptor column number[" + cellWrapper.getColumn() + "] cell value[" + cellWrapper.getValue() + "] cell intercepter[" + interceptor + "]");
	this.intercepterCellValue(cellWrapper, interceptor);
	logger.debug("after interceptor  cell value[" + cellWrapper.getValue() + "]");

}
 
開發者ID:bsteker,項目名稱:bdf2,代碼行數:36,代碼來源:AbstractExcelParser.java

示例5: getCellValue

/**
 * 獲取單元格值
 *
 * @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,代碼行數:41,代碼來源:ImportExcel.java

示例6: getCellType

private int getCellType(Cell cell) {
	int vType = cell.getCellType();
	if (vType == Cell.CELL_TYPE_FORMULA) {
		// 獲取公式類型
		vType = cell.getCachedFormulaResultType();
	}
	return vType;
}
 
開發者ID:xinufo,項目名稱:teemo,代碼行數:8,代碼來源:RowExcelImpl.java

示例7: getValue

@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,代碼行數:34,代碼來源:RowParser.java

示例8: getCellFormatValue

/**
 * 根據HSSFCell類型設置數據(簡單導入使用)
 *
 * @param cell 單元格
 * @return 處理後的值
 */
private static String getCellFormatValue(Cell cell) {
    String cellValue;
    if (cell != null) {
        // 判斷當前Cell的Type
        switch (cell.getCellType()) {
            // 如果當前Cell的Type為NUMERIC
            case Cell.CELL_TYPE_NUMERIC:
            case Cell.CELL_TYPE_FORMULA: {
                // 判斷當前的cell是否為Date
                if (DateUtil.isCellDateFormatted(cell)) {
                    // 如果是Date類型則,轉化為Data格式
                    Date date = cell.getDateCellValue();
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    cellValue = sdf.format(date);
                }
                // 如果是純數字
                else {
                    //避免科學計數
                    java.text.NumberFormat nf = java.text.NumberFormat.getInstance();
                    nf.setGroupingUsed(false);
                    // 取得當前Cell的數值
                    cellValue = String.valueOf(nf.format(cell.getNumericCellValue()));
                }
                break;
            }
            // 如果當前Cell的Type為STRING
            case Cell.CELL_TYPE_STRING:
                // 取得當前的Cell字符串
                cellValue = cell.getStringCellValue();
                break;
            // 默認的Cell值
            default:
                cellValue = " ";
        }
    } else {
        cellValue = "";
    }
    return cellValue;
}
 
開發者ID:goribun,項目名稱:excel-rw-annotation,代碼行數:45,代碼來源:BaseReadUtil.java

示例9: setCellValue

protected void setCellValue(String cellName, String value,boolean notifyUpdate)
{
	
	boolean isNumeric = GeneralUtil.isNumeric(value);
	CellData cellData = getCellDataByCellName(cellName);

	if(cellData.cell == null)
		cellData.cell = createCellBlank(cellName);
	//si es una formula cambio el tipo de celda para setear un numero
	//es el caso de las celdas mixtas que pueden ser formula o un valor ingresado por el usuario
	if (cellData.cell.getCellType() == Cell.CELL_TYPE_FORMULA)
	{
		
	//	System.out.println("cell : " + cellName);
	//	System.out.println("value : " + cellName);
		
		if(isNumeric)
		{
			cellData.cell.setCellType(Cell.CELL_TYPE_NUMERIC);
		}
		else
		{
			cellData.cell.setCellType(Cell.CELL_TYPE_STRING);	
		}
		
	}

	
	if(isNumeric)
	{
		cellData.cell.setCellValue(Double.parseDouble(value));
	}
	else
	{
		
		cellData.cell.setCellValue(value);
	}

		if(notifyUpdate)
		{
			this.notifyUpdateCell(cellData);
			
		}
			
}
 
開發者ID:rodrigoEclipsa,項目名稱:excelToApp,代碼行數:45,代碼來源:ExcelBase.java

示例10: getCellValue

private CellData getCellValue(CellData cellData) 
{

	//CellData cellData = new CellData();

	if(cellData.cell != null)
	{
	// evaluator.evaluateFormulaCell(cell);

	int cellTypeEvaluator = cellData.workBookObject.evaluator.evaluateFormulaCell(cellData.cell);

	int cellType = cellTypeEvaluator > -1 ? cellTypeEvaluator : cellData.cell
			.getCellType();

	switch (cellType)
	{

	case Cell.CELL_TYPE_BLANK:

		// cellData.put("type",HSSFCell.CELL_TYPE_BLANK);
		cellData.value = cellData.cell.getStringCellValue();
		
		break;

	case Cell.CELL_TYPE_NUMERIC:

		// cellData.put("type",HSSFCell.CELL_TYPE_NUMERIC);
		cellData.value = Double.toString(cellData.cell.getNumericCellValue());

		break;

	case Cell.CELL_TYPE_STRING:

		// cellData.put("type",HSSFCell.CELL_TYPE_STRING);
		cellData.value = cellData.cell.getStringCellValue();

		break;

	case Cell.CELL_TYPE_ERROR:

		cellData.error = FormulaError.forInt(cellData.cell.getErrorCellValue()).name();
		cellData.value = "ERROR";

		break;

	case Cell.CELL_TYPE_FORMULA:

		// cellData.put("type", HSSFCell.CELL_TYPE_ERROR);
		cellData.value = cellData.cell.getCellFormula();

		break;

	default:

		// cellData.put("type",HSSFCell.CELL_TYPE_STRING);
		cellData.value = cellData.cell.getCellStyle().getDataFormatString();

	}

	// si la celda es pocentaje multiplico por 100

	if (cellData.cell.getCellStyle().getDataFormatString().contains("%")
			&& cellType == Cell.CELL_TYPE_NUMERIC)
	{

		Double perceValue = Double.parseDouble(cellData.value) * 100;
		cellData.value = perceValue.toString();

	}

	}
	else
	{
		cellData.value = null;
		
	}

	
	return cellData;
}
 
開發者ID:rodrigoEclipsa,項目名稱:excelToApp,代碼行數:80,代碼來源:ExcelBase.java


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