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


Java HSSFDateUtil類代碼示例

本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFDateUtil的典型用法代碼示例。如果您正苦於以下問題:Java HSSFDateUtil類的具體用法?Java HSSFDateUtil怎麽用?Java HSSFDateUtil使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: getCellValue

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入依賴的package包/類
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 "";
	}
}
 
開發者ID:ken8271,項目名稱:parrot,代碼行數:17,代碼來源:XlsParser.java

示例2: getNumericValue

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入依賴的package包/類
/**
 * Return the numeric value.
 *
 * @param cell the cell to extract the value from.
 * @return the numeric value from the cell.
 */
private static String getNumericValue(Cell cell, CellValue cellValue, boolean fromFormula) {
    // Date is typed as numeric
    if (HSSFDateUtil.isCellDateFormatted(cell)) { // TODO configurable??
        DateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH);
        return sdf.format(cell.getDateCellValue());
    }
    // Numeric type (use data formatter to get number format right)
    DataFormatter formatter = new HSSFDataFormatter(Locale.ENGLISH);

    if (cellValue == null) {
        return formatter.formatCellValue(cell);
    }

    return fromFormula ? cellValue.formatAsString() : formatter.formatCellValue(cell);
}
 
開發者ID:Talend,項目名稱:data-prep,代碼行數:22,代碼來源:XlsUtils.java

示例3: getNumericCellValue

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入依賴的package包/類
private Object getNumericCellValue( Cell cell ) {

		double val = cell.getNumericCellValue();

		if( isCellDateFormatted(cell) ) {
			String dateFormat = cell.getCellStyle().getDataFormatString();
			return new CellDateFormatter(dateFormat).format( HSSFDateUtil.getJavaDate(val) );

		} else {

			long fixedVal = (long) val;
			if( val - fixedVal == 0 ) {
				if( fixedVal < Integer.MAX_VALUE ) {
					return (int) fixedVal;
				} else {
					return fixedVal;
				}
			} else {
				return cell.getNumericCellValue();
			}
		}

    }
 
開發者ID:NyBatis,項目名稱:NyBatisCore,代碼行數:24,代碼來源:ExcelHandlerApachePoi.java

示例4: getCellValue

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入依賴的package包/類
public String getCellValue(Cell cell) {
	if (cell == null)
		return ExcelODAConstants.EMPTY_STRING;

	if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
		return resolveFormula(cell);
	}

	if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
		if(	HSSFDateUtil.isCellDateFormatted(cell) ){		
			Date myjavadate =  HSSFDateUtil.getJavaDate(cell.getNumericCellValue());
			return sdf.format( myjavadate );
		}
		return ((Double) cell.getNumericCellValue()).toString();
	}

	return cell.toString();
}
 
開發者ID:eclipse,項目名稱:birt,代碼行數:19,代碼來源:ExcelFileReader.java

示例5: getNativeValueType

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入依賴的package包/類
@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 (HSSFDateUtil.isCellDateFormatted(cell)) {
			return ValueType.DATE;
		} else {
			return ValueType.NUMBER;
		}
	} else if (type == Cell.CELL_TYPE_FORMULA) {
		return ValueType.NUMBER;
	} else {
		return ValueType.STRING;
	}
}
 
開發者ID:rapidminer,項目名稱:rapidminer-5,代碼行數:21,代碼來源:Excel2007ResultSet.java

示例6: cellValues2String

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入依賴的package包/類
/**
 * 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,代碼行數:36,代碼來源:ExcelLoader.java

示例7: parse_number

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入依賴的package包/類
protected CellValue parse_number(Cell in) {
	CellValue rv = null;

	try {
		if(HSSFDateUtil.isCellDateFormatted(in)) {
			rv = new CellValue("datetime", Report.DATEFORMAT_OUT.format(in.getDateCellValue()));
		} else {
			rv = new CellValue("number", Double.toString(in.getNumericCellValue()));				
		}
	} catch(IllegalStateException e) {
		// Siehe Dokumentation getNumericCellValue
		rv = new CellValue("string", in.getStringCellValue());
	}

	return rv;
}
 
開發者ID:michael-simons,項目名稱:enerko-reports2,代碼行數:17,代碼來源:CellDefinition.java

示例8: getCellValue

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入依賴的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

示例9: copyCellByBlankSpace

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入依賴的package包/類
/**
 * 複製單位格(空白行的複製,即隻複製格式和固定文字,不填充數據)
 * 
 * @author      ZhengWei(HY)
 * @createDate  2017-07-03
 * @version     v1.0
 *
 * @param i_RTemplate      模板對象
 * @param i_TemplateCell   模板中的單元格對象
 * @param i_DataWorkbook   數據工作薄
 * @param i_DataCell       數據中的單元格對象
 * @param io_RSystemValue 係統變量信息
 * @param i_Datas          本行對應的數據
 * @param io_RValue        小計循環的迭代器
 * @return                 
 */
public final static void copyCellByBlankSpace(RTemplate i_RTemplate ,Cell i_TemplateCell ,RWorkbook i_DataWorkbook ,Cell i_DataCell ,RSystemValue io_RSystemValue)
{
    // 複製樣式
    i_DataCell.setCellStyle(i_DataWorkbook.getCellStyle(i_RTemplate ,i_TemplateCell.getCellStyle().getIndex()));
    
    // 複製評論
    copyComment(i_RTemplate ,i_TemplateCell ,i_DataWorkbook ,i_DataCell);
    
    // 複製數據類型
    CellType v_CellType = i_TemplateCell.getCellTypeEnum();
    // i_DataCell.setCellType(v_CellType);  不能在此統一設置,原因是:下麵代碼對類型是有浮動的
    
    if ( v_CellType == CellType.NUMERIC ) 
    {
        i_DataCell.setCellType(v_CellType);
        
        if ( HSSFDateUtil.isCellDateFormatted(i_TemplateCell) ) 
        {
            i_DataCell.setCellValue(i_TemplateCell.getDateCellValue());
        } 
        else 
        {
            i_DataCell.setCellValue(i_TemplateCell.getNumericCellValue());
        }
    }
    else if ( v_CellType == CellType.STRING ) 
    {
        RichTextString v_TemplateRichText = i_TemplateCell.getRichStringCellValue();
        String         v_ValueName        = v_TemplateRichText.toString();
        
        if ( i_RTemplate.isExists(v_ValueName) )
        {
            i_DataCell.setCellType(v_CellType);
            i_DataCell.setCellValue("");
        }
        else 
        {
            i_DataCell.setCellType(v_CellType);
            copyRichTextStyle(i_RTemplate ,v_TemplateRichText ,i_DataWorkbook ,i_DataCell);
        }
    } 
    else if ( v_CellType == CellType.BOOLEAN ) 
    {
        i_DataCell.setCellType(v_CellType);
        i_DataCell.setCellValue(i_TemplateCell.getBooleanCellValue());
    } 
    else if ( v_CellType == CellType.FORMULA) 
    {
        i_DataCell.setCellType(v_CellType);
        i_DataCell.setCellFormula(i_TemplateCell.getCellFormula());
    } 
    else 
    {
        // Nothing.
        i_DataCell.setCellType(v_CellType);
    }
}
 
開發者ID:HY-ZhengWei,項目名稱:hy.common.report,代碼行數:74,代碼來源:JavaToExcel.java

示例10: getMsgListFromExcel

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入依賴的package包/類
@Override
public ArrayList<MsgEntity> getMsgListFromExcel(File targetFile) throws IOException {
	ArrayList<MsgEntity> list = new ArrayList<MsgEntity>();
	POIFSFileSystem fs = new POIFSFileSystem(targetFile);
	HSSFWorkbook workBook = new HSSFWorkbook(fs);
	try {
		System.out.println("開始解析");
		HSSFSheet sheet = workBook.getSheetAt(0);
		int rows = sheet.getLastRowNum() + 1;
		for (int r = 1; r < rows; r++) {
			HSSFRow row = sheet.getRow(r);
			if (row == null) {
				continue;
			}
			MsgEntity msg = new MsgEntity();
			String number = getStringVal(row.getCell(0));
			if(StringUtils.isEmpty(number)){
				continue;
			}
			msg.setTelNumber(number);
			
			String templateId = getStringVal(row.getCell(1));
			if (!StringUtils.isEmpty(templateId) && StringUtils.isNumeric(templateId)
					&& templateId.indexOf(".") == -1) {
				msg.setTemplateId(Long.parseLong(templateId));
			}
			msg.setContent(getStringVal(row.getCell(2)));
			if (HSSFDateUtil.isCellDateFormatted(row.getCell(3))) {
				msg.setSendTime(row.getCell(3).getDateCellValue());
			}
			list.add(msg);
		}
		
	} finally {
		workBook.close();
	}
	return list;

}
 
開發者ID:gyp220203,項目名稱:renren-msg,代碼行數:40,代碼來源:ParseExcelServiceImpl.java

示例11: parseAsJsonElement

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入依賴的package包/類
private static JsonElement parseAsJsonElement(Cell cell, FormulaEvaluator evaluator) {
    switch (cell.getCellTypeEnum()) {
        case NUMERIC:
            if (HSSFDateUtil.isCellDateFormatted(cell)) {
                return new JsonPrimitive(DateFormatterHolder.formatter.format(cell.getDateCellValue().toInstant()));
            } else {
                return new JsonPrimitive(cell.getNumericCellValue());
            }
        case STRING:
            return new JsonPrimitive(cell.getStringCellValue());
        case FORMULA:
            CellValue cellValue = evaluator.evaluate(cell);
            switch (cellValue.getCellTypeEnum()) {
                case NUMERIC:
                    return new JsonPrimitive(cellValue.getNumberValue());
                case STRING:
                    return new JsonPrimitive(cellValue.getStringValue());
                case BLANK:
                    return new JsonPrimitive("");
                case BOOLEAN:
                    return new JsonPrimitive(cellValue.getBooleanValue());
                case ERROR:
                default:
                    return null;
            }
        case BLANK:
            return new JsonPrimitive("");
        case BOOLEAN:
            return new JsonPrimitive(cell.getBooleanCellValue());
        case ERROR:
        default:
            return null;
    }
}
 
開發者ID:zjnu-acm,項目名稱:judge,代碼行數:35,代碼來源:ExcelUtil.java

示例12: getValue

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入依賴的package包/類
public static String getValue(Cell cell) throws Exception {
	String temp = null;

	if (cell != null) {
		SimpleDateFormat f = new SimpleDateFormat(YYYY_MM_DD);

		switch (cell.getCellType()) {
		case Cell.CELL_TYPE_NUMERIC:
			// 셀값이 날짜일경우
			if (HSSFDateUtil.isCellDateFormatted(cell)) {
				temp = f.format(cell.getDateCellValue());
				// 셀값이 숫자일경우
			} else {
				temp = String.valueOf(cell.getNumericCellValue());
			}
			break;
		case Cell.CELL_TYPE_STRING:
			temp = cell.getStringCellValue();
			break;
		case Cell.CELL_TYPE_FORMULA:
			temp = cell.getCellFormula();
			break;
		/*
		 * case Cell.CELL_TYPE_BLANK: temp = ""; break;
		 */
		case Cell.CELL_TYPE_BOOLEAN:
			temp = String.valueOf(cell.getBooleanCellValue());
			break;
		default:
			temp = "";
			break;
		}

	}
	return temp;
}
 
開發者ID:callakrsos,項目名稱:Gargoyle,代碼行數:37,代碼來源:ExcelUtil.java

示例13: isNum

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入依賴的package包/類
public boolean isNum(Sheet sheet, int rowInt, int column) {
	Row row = sheet.getRow(rowInt);
	Cell cell = row.getCell(column);
	boolean resultBoolean = false;
	if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
		if (!HSSFDateUtil.isCellDateFormatted(cell)) {
			resultBoolean = true;
		}
	}
	return resultBoolean;
}
 
開發者ID:callakrsos,項目名稱:Gargoyle,代碼行數:12,代碼來源:ExcelUtil.java

示例14: getCellFormatValue

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入依賴的package包/類
/**
 * 根據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;
}
 
開發者ID:xuegongzi,項目名稱:rabbitframework,代碼行數:46,代碼來源:ExcelUploadParse.java

示例15: getTypeFromNumericCell

import org.apache.poi.hssf.usermodel.HSSFDateUtil; //導入依賴的package包/類
private String getTypeFromNumericCell(Cell cell) {
    try {
        return HSSFDateUtil.isCellDateFormatted(cell) ? DATE.getName() : NUMERIC.getName();
    } catch (IllegalStateException e) {
        return ANY.getName();
    }
}
 
開發者ID:Talend,項目名稱:data-prep,代碼行數:8,代碼來源:XlsSchemaParser.java


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