本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFCell.getNumericCellValue方法的典型用法代码示例。如果您正苦于以下问题:Java HSSFCell.getNumericCellValue方法的具体用法?Java HSSFCell.getNumericCellValue怎么用?Java HSSFCell.getNumericCellValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.hssf.usermodel.HSSFCell
的用法示例。
在下文中一共展示了HSSFCell.getNumericCellValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIntCellValue
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public static int getIntCellValue(HSSFSheet sheet, int r, int c) {
HSSFRow row = sheet.getRow(r);
if (row == null) {
return 0;
}
HSSFCell cell = row.getCell(c);
try {
if (cell.getCellType() != HSSFCell.CELL_TYPE_NUMERIC) {
return 0;
}
} catch (RuntimeException e) {
System.err.println("Exception at sheet name:"
+ sheet.getSheetName() + ", row:" + (r + 1) + ", col:"
+ (c + 1));
throw e;
}
return (int) cell.getNumericCellValue();
}
示例2: parseBooleanCell
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private boolean parseBooleanCell(HSSFCell cell) {
if (cell != null) {
String value;
try {
cell.setCellType(Cell.CELL_TYPE_STRING);
if (cell.getStringCellValue() != null) {
if (cell.getStringCellValue().trim().length() != 0) {
emptyRow = false;
}
} else {
return false;
}
value = cell.getStringCellValue().trim();
} catch (Exception e) {
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
double d = cell.getNumericCellValue();
emptyRow = false;
value = new Long(new Double(d).longValue()).toString();
}
if (StringUtils.equals(value, "1") || StringUtils.equalsIgnoreCase(value, "true")) {
return true;
}
}
return false;
}
示例3: parseStringCell
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private String parseStringCell(HSSFCell cell) {
if (cell != null) {
try {
cell.setCellType(Cell.CELL_TYPE_STRING);
if (cell.getStringCellValue() != null) {
if (cell.getStringCellValue().trim().length() != 0) {
emptyRow = false;
}
} else {
return null;
}
// log.debug("string cell value: '"+cell.getStringCellValue().trim()+"'");
return cell.getStringCellValue().trim();
} catch (Exception e) {
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
double d = cell.getNumericCellValue();
emptyRow = false;
// log.debug("numeric cell value: '"+d+"'");
return (new Long(new Double(d).longValue()).toString());
}
}
return null;
}
示例4: getIntCellValue
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public static int getIntCellValue(final HSSFSheet sheet, final int r, final int c) {
final HSSFRow row = sheet.getRow(r);
if (row == null) {
return 0;
}
final HSSFCell cell = row.getCell(c);
try {
if (cell.getCellType() != Cell.CELL_TYPE_NUMERIC) {
return 0;
}
} catch (final RuntimeException e) {
System.err.println("Exception at sheet name:" + sheet.getSheetName() + ", row:" + (r + 1) + ", col:" + (c + 1));
throw e;
}
return (int) cell.getNumericCellValue();
}
示例5: fromHSSFRowtoCSV
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private String fromHSSFRowtoCSV(HSSFRow row){
StringBuffer csvRow = new StringBuffer();
int l = row.getLastCellNum();
for (int i=0;i<l;i++){
HSSFCell 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();
}
示例6: getStringValueOfCell
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private String getStringValueOfCell(HSSFCell cell, int cellType) {
switch (cellType) {
case Cell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue() ? "Ja" : "Nein";
case Cell.CELL_TYPE_FORMULA:
return getStringValueOfCell(cell, cell.getCachedFormulaResultType());
case Cell.CELL_TYPE_NUMERIC:
double number = cell.getNumericCellValue();
if(Double.isInfinite(number) || Double.isNaN(number) || Math.floor(number) != number)
return Double.toString(number);
else
return String.valueOf(new Double(number).intValue());
case Cell.CELL_TYPE_STRING:
return cell.getStringCellValue();
}
AtomTools.log(Level.SEVERE, "unknown celltype: " + cellType + "; content of cell = " + cell.toString(), this);
return null;
}
示例7: manageInteger
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private Integer manageInteger(PreparedStatement ps, PreparedStatement psUpdate, int lfdCol, HSSFCell cell) throws SQLException {
Integer result = null;
if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
if (cell.getStringCellValue().trim().length() > 0) {
result = new Integer(cell.getStringCellValue());
if (ps != null) ps.setInt(lfdCol, result);
if (psUpdate != null) psUpdate.setInt(lfdCol, result);
return result;
}
} else {
result = new Integer((int) cell.getNumericCellValue());
if (ps != null) ps.setInt(lfdCol, result);
if (psUpdate != null) psUpdate.setInt(lfdCol, result);
return result;
}
if (ps != null) ps.setNull(lfdCol, java.sql.Types.INTEGER);
if (psUpdate != null) psUpdate.setNull(lfdCol, java.sql.Types.INTEGER);
return result;
}
示例8: manageBigInteger
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private Long manageBigInteger(PreparedStatement ps, PreparedStatement psUpdate, int lfdCol, HSSFCell cell) throws SQLException {
Long result = null;
if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
if (cell.getStringCellValue().trim().length() > 0) {
result = new Long(cell.getStringCellValue());
if (ps != null) ps.setLong(lfdCol, result);
if (psUpdate != null) psUpdate.setLong(lfdCol, result);
return result;
}
} else {
result = new Long((long) cell.getNumericCellValue());
if (ps != null) ps.setLong(lfdCol, result);
if (psUpdate != null) psUpdate.setLong(lfdCol, result);
return result;
}
if (ps != null) ps.setNull(lfdCol, java.sql.Types.BIGINT);
if (psUpdate != null) psUpdate.setNull(lfdCol, java.sql.Types.BIGINT);
return result;
}
示例9: manageBoolean
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private Boolean manageBoolean(PreparedStatement ps, PreparedStatement psUpdate, int lfdCol, HSSFCell cell) throws SQLException {
Boolean result = null;
if (cell == null || cell.getCellType() == HSSFCell.CELL_TYPE_BLANK) {
if (ps != null) ps.setNull(lfdCol, java.sql.Types.BOOLEAN);
if (psUpdate != null) psUpdate.setNull(lfdCol, java.sql.Types.BOOLEAN);
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
result = cell.getNumericCellValue() != 0;
if (ps != null) ps.setBoolean(lfdCol, result);
if (psUpdate != null) psUpdate.setBoolean(lfdCol, result);
} else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
result = cell.getStringCellValue().equalsIgnoreCase("true");
if (ps != null) ps.setBoolean(lfdCol, result);
if (psUpdate != null) psUpdate.setBoolean(lfdCol, result);
} else {
result = cell.getBooleanCellValue();
if (ps != null) ps.setBoolean(lfdCol, result);
if (psUpdate != null) psUpdate.setBoolean(lfdCol, result);
}
//ps.setNull(lfdCol, java.sql.Types.BOOLEAN);
return result;
}
示例10: getValueFromCell
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
/**
* <b>描述:</b> 从单元格中获取到的数据
* @param cell 单元格对应的HSSFCell对象
* @return Object 从单元格中获取到的数据
*/
private Object getValueFromCell(HSSFCell cell){
if(cell==null)return "";
switch(cell.getCellType()){
case HSSFCell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue();
case HSSFCell.CELL_TYPE_NUMERIC:
return cell.getNumericCellValue();
case HSSFCell.CELL_TYPE_FORMULA:
return cell.getCellFormula();
case HSSFCell.CELL_TYPE_STRING:
return cell.getRichStringCellValue().toString();
default:
return cell.getRichStringCellValue().toString();
}
}
示例11: readRecord
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public Map<String,String> readRecord() throws ReadException {
HSSFRow row = currentSheet.getRow(nextRowNumber);
if (row!=null){
//We have data.
Map<String,String> result = new HashMap<String,String>(schema.length);
//Do not use the iterator (row.cellIterator()): this will cause to skip empty cells!
//Use the schema to loop over the cells
for (short i = 0; i < schema.length; i++) {
String fieldName = schema[i];
HSSFCell cel = row.getCell(i);
if (cel != null){
String value="";
if (cel.getCellType()==HSSFCell.CELL_TYPE_NUMERIC){
// TODO: make this configurable: conversion from double to string
value = cel.getNumericCellValue()+"";
}else{
value = cel.getStringCellValue();
}
result.put(fieldName, value);
}
else
{
result.put(fieldName, "");
}
}
nextRowNumber++;
return result;
}
else
{
return null;
}
}
示例12: getCellString
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private Object getCellString(HSSFCell cell) {
// TODO Auto-generated method stub
Object result = null;
if (cell != null) {
// 单元格类型:Numeric:0,String:1,Formula:2,Blank:3,Boolean:4,Error:5
int cellType = cell.getCellType();
switch (cellType) {
case HSSFCell.CELL_TYPE_STRING:
result = cell.getRichStringCellValue().getString();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
result = cell.getNumericCellValue();
break;
case HSSFCell.CELL_TYPE_FORMULA:
result = cell.getNumericCellValue();
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
result = cell.getBooleanCellValue();
break;
case HSSFCell.CELL_TYPE_BLANK:
result = null;
break;
case HSSFCell.CELL_TYPE_ERROR:
result = null;
break;
default:
System.out.println("枚举了所有类型");
break;
}
}
return result;
}
示例13: getDateValueFromJavaNumber
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
protected Object getDateValueFromJavaNumber(HSSFCell cell) {
logger.debug("getDateValueFromJavaNumber(cell={}) - start", cell);
double numericValue = cell.getNumericCellValue();
BigDecimal numericValueBd = new BigDecimal(String.valueOf(numericValue));
numericValueBd = stripTrailingZeros(numericValueBd);
return new Long(numericValueBd.longValue());
// return new Long(numericValueBd.unscaledValue().longValue());
}
示例14: getNumericValue
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
protected BigDecimal getNumericValue(HSSFCell cell) {
logger.debug("getNumericValue(cell={}) - start", cell);
String formatString = cell.getCellStyle().getDataFormatString();
String resultString = null;
double cellValue = cell.getNumericCellValue();
if ((formatString != null)) {
if (!formatString.equals("General") && !formatString.equals("@")) {
logger.debug("formatString={}", formatString);
DecimalFormat nf = new DecimalFormat(formatString, symbols);
resultString = nf.format(cellValue);
}
}
BigDecimal result;
if (resultString != null) {
try {
result = new BigDecimal(resultString);
} catch (NumberFormatException e) {
logger.debug("Exception occurred while trying create a BigDecimal. value={}", resultString);
// Probably was not a BigDecimal format retrieved from the
// excel. Some
// date formats are not yet recognized by HSSF as DateFormats so
// that
// we could get here.
result = toBigDecimal(cellValue);
}
} else {
result = toBigDecimal(cellValue);
}
return result;
}
示例15: getDoubleValueOfCell
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private Double getDoubleValueOfCell(HSSFCell cell, int cellType) {
switch (cellType) {
case Cell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue() ? new Double(1) : new Double(0);
case Cell.CELL_TYPE_FORMULA:
return getDoubleValueOfCell(cell, cell.getCachedFormulaResultType());
case Cell.CELL_TYPE_NUMERIC:
// TO DO apply the dataformat for this cell
// if (HSSFDateUtil.isCellDateFormatted(cell)) {
// DateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
// return sdf.format(cell.getDateCellValue());
// }
return cell.getNumericCellValue();
// return value.intValue();
case Cell.CELL_TYPE_STRING:
return Double.parseDouble(cell.getStringCellValue());
default:
AtomTools.log(Level.SEVERE, "unknown celltype: " + cellType + "; content of cell = " + cell.toString(), this);
return null;
}
}