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


Java XSSFCell.CELL_TYPE_NUMERIC屬性代碼示例

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


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

示例1: getCellValue

/**
 * Gets the cell value.
 *
 * @param cell the cell
 * @return the cell value
 */
private String getCellValue( XSSFCell cell )
{
	if (cell != null)
	{
		switch (cell.getCellType())
		{
			case XSSFCell.CELL_TYPE_BLANK:
				return null;
			case XSSFCell.CELL_TYPE_BOOLEAN:
				return String.valueOf( cell.getBooleanCellValue() );
			case XSSFCell.CELL_TYPE_NUMERIC:
				return String.valueOf( ( int ) cell.getNumericCellValue() );
			case XSSFCell.CELL_TYPE_STRING:
				return cell.getRichStringCellValue().toString();

		}
	}
	return null;
}
 
開發者ID:xframium,項目名稱:xframium-java,代碼行數:25,代碼來源:ExcelDataProvider.java

示例2: getCellValue

/**
 * Gets the cell value.
 *
 * @param cell the cell
 * @return the cell value
 */
private String getCellValue( XSSFCell cell )
{
	if (cell != null)
	{
		switch (cell.getCellType())
		{
			case XSSFCell.CELL_TYPE_BLANK:
				return null;
			case XSSFCell.CELL_TYPE_BOOLEAN:
				return String.valueOf( cell.getBooleanCellValue() );
			case XSSFCell.CELL_TYPE_NUMERIC:
				return String.valueOf( cell.getNumericCellValue() );
			case XSSFCell.CELL_TYPE_STRING:
				return cell.getRichStringCellValue().toString();
		}
	}
	return null;
}
 
開發者ID:xframium,項目名稱:xframium-java,代碼行數:24,代碼來源:ExcelCloudProvider.java

示例3: getCellValue

/**
 * Gets the cell value.
 *
 * @param cell the cell
 * @return the cell value
 */
private String getCellValue( XSSFCell cell )
{
	if (cell != null)
	{
		switch (cell.getCellType())
		{
			case XSSFCell.CELL_TYPE_BLANK:
				return null;
			case XSSFCell.CELL_TYPE_BOOLEAN:
				return String.valueOf( cell.getBooleanCellValue() );
			case XSSFCell.CELL_TYPE_NUMERIC:
			{
			    String useValue = String.valueOf( cell.getNumericCellValue() );
			    if ( useValue.endsWith( ".0" ) )
			        return useValue.split( "\\." )[0];
			    else
			        return useValue;
			}
			case XSSFCell.CELL_TYPE_STRING:
				return cell.getRichStringCellValue().toString();
		}
	}
	return null;
}
 
開發者ID:xframium,項目名稱:xframium-java,代碼行數:30,代碼來源:ExcelPageDataProvider.java

示例4: getCellValue

private String getCellValue( XSSFCell cell )
{
    if (cell != null )
    {
        switch (cell.getCellType())
        {
            case XSSFCell.CELL_TYPE_BLANK:
                return null;
            case XSSFCell.CELL_TYPE_BOOLEAN:
                return String.valueOf( cell.getBooleanCellValue() );
            case XSSFCell.CELL_TYPE_NUMERIC:
                return String.valueOf( cell.getNumericCellValue() );
            case XSSFCell.CELL_TYPE_STRING:
                return cell.getRichStringCellValue().toString();
        }
    }
    return null;
}
 
開發者ID:xframium,項目名稱:xframium-java,代碼行數:18,代碼來源:ExcelKeyWordProvider.java

示例5: stringValueOf

protected String stringValueOf(CellValue value) {
    switch (value.getCellType()) {
        case XSSFCell.CELL_TYPE_STRING:
            return value.getStringValue();
        case XSSFCell.CELL_TYPE_NUMERIC:
            return String.valueOf(value.getNumberValue());
        case XSSFCell.CELL_TYPE_BLANK:
            return "";
        case XSSFCell.CELL_TYPE_BOOLEAN:
            return String.valueOf(value.getBooleanValue());
        case XSSFCell.CELL_TYPE_ERROR:
            return "error";
        default:
            return "unknown";
    }
}
 
開發者ID:aalexandrov,項目名稱:arch-tools,代碼行數:16,代碼來源:ClusteringService.java

示例6: getCellTypeName

/**
 * 獲取單元格類型名稱
 *
 * @param cell
 * @return
 *
 */
public static String getCellTypeName(XSSFCell cell) {
    if (cell == null) {
        return "null";
    }

    switch (cell.getCellType()) {
    case XSSFCell.CELL_TYPE_BLANK: return "CELL_TYPE_BLANK";
    case XSSFCell.CELL_TYPE_BOOLEAN: return "CELL_TYPE_BOOLEAN";
    case XSSFCell.CELL_TYPE_ERROR: return "CELL_TYPE_ERROR";
    case XSSFCell.CELL_TYPE_FORMULA: return "CELL_TYPE_FORMULA";
    case XSSFCell.CELL_TYPE_NUMERIC: return "CELL_TYPE_NUMERIC";
    case XSSFCell.CELL_TYPE_STRING: return "CELL_TYPE_STRING";
    default: return "unknown";
    }
}
 
開發者ID:hjj2017,項目名稱:xgame-code_server,代碼行數:22,代碼來源:XSSFUtil.java

示例7: cellValues2String

/**
 * Get the value of the excel-cell as String.
 * 
 * @param workbook
 *            workbook (excel) for evaluating cell formulas
 * @param cell
 *            cell (excel)
 * 
 * @return the value of the excel-cell as String
 */
static String cellValues2String(XSSFWorkbook workbook, XSSFCell cell) {
	if (cell == null) {
		return null;
	}
	switch (cell.getCellType()) {
	case XSSFCell.CELL_TYPE_NUMERIC:
		if (HSSFDateUtil.isCellDateFormatted(cell)) {
			return new SimpleDateFormat(JExUnitConfig.getStringProperty(JExUnitConfig.ConfigKey.DATE_PATTERN))
					.format(cell.getDateCellValue());
		} else {
			return String.valueOf(cell.getNumericCellValue());
		}
	case XSSFCell.CELL_TYPE_STRING:
		return cell.getStringCellValue();
	case XSSFCell.CELL_TYPE_FORMULA:
		return evaluateCellFormula(workbook, cell);
	case XSSFCell.CELL_TYPE_BLANK:
		return cell.getStringCellValue();
	case XSSFCell.CELL_TYPE_BOOLEAN:
		return String.valueOf(cell.getBooleanCellValue());
	case XSSFCell.CELL_TYPE_ERROR:
		return String.valueOf(cell.getErrorCellValue());
	}
	return null;
}
 
開發者ID:fhm84,項目名稱:jexunit,代碼行數:35,代碼來源:ExcelLoader.java

示例8: getValue

private static String getValue(XSSFCell xssFCell) {
	 String str = null;
	 if(xssFCell == null){
		 return str;
	 }
	 if (xssFCell.getCellType() == XSSFCell.CELL_TYPE_BOOLEAN) {
		 str = String.valueOf(xssFCell.getBooleanCellValue());
	 } else if (xssFCell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
		 str = String.valueOf(new DecimalFormat("#").format(xssFCell.getNumericCellValue()));
	 } else {
		 str = String.valueOf(xssFCell.getStringCellValue());
	 }
	 return StringUtils.trim(str);
}
 
開發者ID:xujeff,項目名稱:tianti,代碼行數:14,代碼來源:ExcelUtils.java

示例9: copyCell

/**
 * @param oldCell
 * @param newCell
 * @param styleMap
 */
public static void copyCell(XSSFCell oldCell, XSSFCell newCell, Map<Integer, XSSFCellStyle> styleMap) {
    if (styleMap != null) {
        if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()) {
            newCell.setCellStyle(oldCell.getCellStyle());
        } else {
            int stHashCode = oldCell.getCellStyle().hashCode();
            XSSFCellStyle newCellStyle = styleMap.get(stHashCode);
            if (newCellStyle == null) {
                newCellStyle = newCell.getSheet().getWorkbook().createCellStyle();
                newCellStyle.cloneStyleFrom(oldCell.getCellStyle());
                styleMap.put(stHashCode, newCellStyle);
            }
            newCell.setCellStyle(newCellStyle);
        }
    }
    switch (oldCell.getCellType()) {
        case XSSFCell.CELL_TYPE_STRING:
            newCell.setCellValue(oldCell.getStringCellValue());
            break;
        case XSSFCell.CELL_TYPE_NUMERIC:
            newCell.setCellValue(oldCell.getNumericCellValue());
            break;
        case XSSFCell.CELL_TYPE_BLANK:
            newCell.setCellType(XSSFCell.CELL_TYPE_BLANK);
            break;
        case XSSFCell.CELL_TYPE_BOOLEAN:
            newCell.setCellValue(oldCell.getBooleanCellValue());
            break;
        case XSSFCell.CELL_TYPE_ERROR:
            newCell.setCellErrorValue(oldCell.getErrorCellValue());
            break;
        case XSSFCell.CELL_TYPE_FORMULA:
            newCell.setCellFormula(oldCell.getCellFormula());
            break;
        default:
            break;
    }

}
 
開發者ID:likelet,項目名稱:DAtools,代碼行數:44,代碼來源:Util.java

示例10: extractDataFromXls

private static JSONArray extractDataFromXls(XSSFWorkbook wb) {
    XSSFSheet sheet = wb.getSheetAt(0);

    int rows = sheet.getPhysicalNumberOfRows();
    int cols = sheet.getRow(0).getPhysicalNumberOfCells();
    int startRow = 1; // Pular cabecalho.

    JsonObjectCreator jsonObjCreator = new FedDepJsonObjectCreator();
    JSONArray jArr = new JSONArray();
    for(int row = startRow; row < rows; row++) {
        XSSFRow xssfRow = sheet.getRow(row);
        if(xssfRow != null) {

            String[] rowData = new String[cols];
            for(int col = 0; col < cols; col++) {
                XSSFCell cell = xssfRow.getCell(col);
                if(cell != null) {
                    String datum;
                    if (XSSFCell.CELL_TYPE_STRING == cell.getCellType()) {
                        datum = cell.getStringCellValue();
                    }
                    else if (XSSFCell.CELL_TYPE_NUMERIC == cell.getCellType()) {
                        datum = String.valueOf(cell.getNumericCellValue());
                    }
                    else {
                        System.out.println("A célula: [" + row + "," + col + "] não contém um String e nem um Número.");
                        datum = "";
                    }

                    rowData[col] = datum;
                }
            }

            JSONObject jObj = jsonObjCreator.processLine(rowData);
            jArr.add(jObj);
        }
    }

    return jArr;
}
 
開發者ID:TekkLabs,項目名稱:memoria-politica,代碼行數:40,代碼來源:FedDepXlsxConverter.java

示例11: getIntCellVal

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

示例12: getLongCellVal

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

示例13: getShortCellVal

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

示例14: getFloatCellVal

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

示例15: getDoubleCellVal

/**
 * 獲取單元格雙精度數值
 *
 * @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,代碼行數:46,代碼來源:XSSFUtil.java


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