本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFCell.CELL_TYPE_NUMERIC屬性的典型用法代碼示例。如果您正苦於以下問題:Java HSSFCell.CELL_TYPE_NUMERIC屬性的具體用法?Java HSSFCell.CELL_TYPE_NUMERIC怎麽用?Java HSSFCell.CELL_TYPE_NUMERIC使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.apache.poi.hssf.usermodel.HSSFCell
的用法示例。
在下文中一共展示了HSSFCell.CELL_TYPE_NUMERIC屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getCellValue
private String getCellValue(HSSFCell cell){
if(cell == null) return "";
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING: return cell.getStringCellValue();
case HSSFCell.CELL_TYPE_BOOLEAN : return Boolean.toString(cell.getBooleanCellValue());
case HSSFCell.CELL_TYPE_NUMERIC :
if(HSSFDateUtil.isCellDateFormatted(cell))
return DateUtils.formatDateTime("yyyyMMdd", HSSFDateUtil.getJavaDate(cell.getNumericCellValue()));
else
return new BigDecimal(cell.getNumericCellValue()).toPlainString();
case HSSFCell.CELL_TYPE_FORMULA : return "";
case HSSFCell.CELL_TYPE_BLANK : return "";
default:return "";
}
}
示例2: getIntCellValue
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();
}
示例3: fromHSSFRowtoCSV
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();
}
示例4: fromXSSFRowtoCSV
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();
}
示例5: getCellValue
private Object getCellValue(Cell cellObject) {
Object cellValue = null;
if (cellObject != null) {
switch (cellObject.getCellType()) {
case HSSFCell.CELL_TYPE_BOOLEAN:
cellValue = cellObject.getBooleanCellValue();
break;
case HSSFCell.CELL_TYPE_STRING:
cellValue = cellObject.getStringCellValue();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
if (DateUtil.isCellDateFormatted(cellObject)) {
cellValue = cellObject.getDateCellValue();
} else {
cellValue = cellObject.getNumericCellValue();
}
break;
default:
break;
}
}
return cellValue;
}
示例6: manageBoolean
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;
}
示例7: getValueFromCell
/**
* <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();
}
}
示例8: getCellData
/**
* Get cell value based on the excel column data type
*
* @param myCell
* @return
*/
private static String getCellData(HSSFCell myCell) throws Exception {
String cellData = "";
if (myCell == null) {
cellData += CVS_SEPERATOR_CHAR;;
} else {
switch (myCell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
case HSSFCell.CELL_TYPE_BOOLEAN:
cellData += myCell.getRichStringCellValue() + CVS_SEPERATOR_CHAR;
break;
case HSSFCell.CELL_TYPE_NUMERIC:
cellData += getNumericValue(myCell);
break;
case HSSFCell.CELL_TYPE_FORMULA:
cellData += getFormulaValue(myCell);
default:
cellData += CVS_SEPERATOR_CHAR;
;
}
}
return cellData;
}
示例9: getCellStringValue
public static String getCellStringValue(HSSFCell cell) {
String cellValue = "";
switch (cell.getCellType()) {
case HSSFCell.CELL_TYPE_STRING:
cellValue = cell.getStringCellValue();
if (cellValue.trim().equals("") || cellValue.trim().length() <= 0) {
cellValue = " ";
}
break;
case HSSFCell.CELL_TYPE_NUMERIC:
// cellValue = String.valueOf(cell.getNumericCellValue());
DecimalFormat formatter = new DecimalFormat("######");
cellValue = formatter.format(cell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_FORMULA:
cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
cellValue = String.valueOf(cell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
cellValue = " ";
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
break;
case HSSFCell.CELL_TYPE_ERROR:
break;
default:
break;
}
return cellValue;
}
示例10: copyCell
/**
* @param oldCell
* @param newCell
* @param styleMap
*/
public static void copyCell(HSSFCell oldCell, HSSFCell newCell, Map<Integer, HSSFCellStyle> styleMap) {
if (styleMap != null) {
if (oldCell.getSheet().getWorkbook() == newCell.getSheet().getWorkbook()) {
newCell.setCellStyle(oldCell.getCellStyle());
} else {
int stHashCode = oldCell.getCellStyle().hashCode();
HSSFCellStyle 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 HSSFCell.CELL_TYPE_STRING:
newCell.setCellValue(oldCell.getStringCellValue());
break;
case HSSFCell.CELL_TYPE_NUMERIC:
newCell.setCellValue(oldCell.getNumericCellValue());
break;
case HSSFCell.CELL_TYPE_BLANK:
newCell.setCellType(HSSFCell.CELL_TYPE_BLANK);
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
newCell.setCellValue(oldCell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_ERROR:
newCell.setCellErrorValue(oldCell.getErrorCellValue());
break;
case HSSFCell.CELL_TYPE_FORMULA:
newCell.setCellFormula(oldCell.getCellFormula());
break;
default:
break;
}
}
示例11: getCellFormatValue
/**
* 根據HSSFCell類型設置數據
*
* @param cell
* @return
*/
private String getCellFormatValue(Cell cell) {
String cellvalue = "";
if (cell != null) {
// 判斷當前Cell的Type
switch (cell.getCellType()) {
// 如果當前Cell的Type為NUMERIC
case HSSFCell.CELL_TYPE_NUMERIC:
case HSSFCell.CELL_TYPE_FORMULA: {
// 判斷當前的cell是否為Date
if (HSSFDateUtil.isCellDateFormatted(cell)) {
// 如果是Date類型則,轉化為Data格式
// 方法1:這樣子的data格式是帶時分秒的:2011-10-12 0:00:00
// cellvalue = cell.getDateCellValue().toLocaleString();
// 方法2:這樣子的data格式是不帶帶時分秒的:2011-10-12
Date date = cell.getDateCellValue();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
cellvalue = sdf.format(date);
}
// 如果是純數字
else {
// 取得當前Cell的數值
cellvalue = String.valueOf(cell.getNumericCellValue());
}
break;
}
// 如果當前Cell的Type為STRIN
case HSSFCell.CELL_TYPE_STRING:
// 取得當前的Cell字符串
cellvalue = cell.getRichStringCellValue().getString();
break;
// 默認的Cell值
default:
cellvalue = " ";
}
} else {
cellvalue = "";
}
return cellvalue;
}
示例12: readRecord
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;
}
}
示例13: checkCellEntries
private boolean checkCellEntries(Iterator<Cell> cells)
{
boolean type = false;
while (cells.hasNext())
{
HSSFCell cell = (HSSFCell) cells.next();
switch (cell.getCellType())
{
case HSSFCell.CELL_TYPE_NUMERIC:
type = false;
break;
case HSSFCell.CELL_TYPE_STRING:
if (cell.getStringCellValue().length() < 100)
{
type = true;
}
else
{
type = false;
}
break;
default:
type = false;
break;
}
if (!type)
{
return false;
}
}
return true;
}
示例14: getCellValue
private BigDecimal getCellValue(int _i, int _index) {
Cell c = getCell(_i, _index);
if (c.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
return new BigDecimal(c.getNumericCellValue()).setScale(2, RoundingMode.HALF_UP);
}
return BigDecimal.ZERO;
}
示例15: getCellData
@SuppressWarnings("null")
public static String getCellData(String reqValue, HSSFSheet reqSheet,
int rowIndex, HashMap<String, Object> inputHashTable)
throws IOException {
HSSFCell reqCell = null;
Object actualvalue = null;
String req = "";
DataFormatter fmt = new DataFormatter();
if (inputHashTable.isEmpty() == true) {
inputHashTable = getValueFromHashMap(reqSheet);
}
HSSFRow rowActual = reqSheet.getRow(rowIndex);
if (inputHashTable.get(reqValue) == null) {
report.setStrMessage("Column " + reqValue
+ " not Found. Please Check input Sheet");
pauseFun("Column " + reqValue
+ " not Found. Please Check input Sheet");
} else {
actualvalue = inputHashTable.get(reqValue);// rowHeader.getCell(colIndex).toString();
if (actualvalue != null) {
int colIndex = Integer.parseInt(actualvalue.toString());
reqCell = rowActual.getCell(colIndex);
if (reqCell == null) {
System.out.println(reqValue + " is Null");
} else {
int type = reqCell.getCellType();
switch (type) {
case HSSFCell.CELL_TYPE_BLANK:
req = "";
break;
case HSSFCell.CELL_TYPE_NUMERIC:
req = fmt.formatCellValue(reqCell);
break;
case HSSFCell.CELL_TYPE_STRING:
req = reqCell.getStringCellValue();
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
req = Boolean.toString(reqCell.getBooleanCellValue());
break;
case HSSFCell.CELL_TYPE_ERROR:
req = "error";
break;
case HSSFCell.CELL_TYPE_FORMULA:
req = reqCell.getCellFormula();
break;
}
}
}
else {
req = reqCell.getStringCellValue();
System.out.println("null");
}
}
return req;
}