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


Java Cell.getDateCellValue方法代碼示例

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


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

示例1: intercepterCellValue

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
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,代碼行數:37,代碼來源:AbstractExcelParser.java

示例2: getValue

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
@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,代碼行數:35,代碼來源:RowParser.java

示例3: getCellFormatValue

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
/**
 * 根據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,代碼行數:46,代碼來源:BaseReadUtil.java

示例4: read

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
private List<List<String>> read(Workbook wb, int sheetIndex) {
    List<List<String>> dataLst = Lists.newArrayList();
    Sheet sheet = wb.getSheetAt(sheetIndex);
    this.totalRows = sheet.getPhysicalNumberOfRows();
    if ((this.totalRows >= 1) && (sheet.getRow(0) != null)) {
        this.totalCells = sheet.getRow(0).getLastCellNum(); // 獲取最後一個不為空的列是第幾個
    }
    for (int r = 0; r < this.totalRows; r++) {
        Row row = sheet.getRow(r);
        if (row != null) {
            List<String> rowLst = Lists.newArrayList();
            for (int c = 0; c < getTotalCells(); c++) {
                Cell cell = row.getCell(c);

                String cellValue = "";
                if (cell != null) {
                    switch (cell.getCellType()) {
                        case 0:
                            if (HSSFDateUtil.isCellDateFormatted(cell)) {
                                Date date = cell.getDateCellValue();

                                cellValue = DateUtils.dateToStr(date,
                                        "yyyy-MM-dd HH:mm:ss");

                            } else {
                                Integer num = (int) cell.getNumericCellValue();
                                cellValue = String.valueOf(num);
                            }
                            break;
                        case 1:
                            cellValue = cell.getStringCellValue().trim();
                            break;
                        case 4:
                            cellValue = String.valueOf(cell.getBooleanCellValue());
                            break;
                        case 2:
                            cellValue = cell.getCellFormula();
                            break;
                        case 3:
                            cellValue = "";
                            break;
                        case 5:
                            cellValue = "非法字符";
                            break;
                        default:
                            cellValue = "未知類型";
                    }
                }
                rowLst.add(cellValue);
            }
            dataLst.add(rowLst);
        }
    }
    return dataLst;
}
 
開發者ID:DreamYa0,項目名稱:zeratul,代碼行數:56,代碼來源:HandleExcel.java

示例5: getDateValue

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
private Date getDateValue(Cell cell) {
	if (HSSFDateUtil.isCellDateFormatted(cell)) {
		return cell.getDateCellValue();
	}
	throw new IllegalArgumentException("Can't get Date because type of cell is not Date");
}
 
開發者ID:xinufo,項目名稱:teemo,代碼行數:7,代碼來源:RowExcelImpl.java

示例6: getDate

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
public Date getDate (int index) {
	Sheet sheet =  getOrCreateSummary();
	Row row = sheet.getRow(index);
	Cell cell = row.getCell(DATE_FORMAT_COLUMN_INDEX);
	return cell.getDateCellValue();
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:7,代碼來源:XLTestSummarySheet.java

示例7: getCellDate

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
private static Date getCellDate(Cell cell) {
    if (HSSFDateUtil.isCellDateFormatted(cell)) {// 處理日期格式、時間格式
        return cell.getDateCellValue();
    }
    return DateUtil.getJavaDate(cell.getNumericCellValue());
}
 
開發者ID:dengxiangjun,項目名稱:OfficeAutomation,代碼行數:7,代碼來源:CellConvert.java

示例8: readDatas

import org.apache.poi.ss.usermodel.Cell; //導入方法依賴的package包/類
public final static PartitionMap<String ,RCell> readDatas(Sheet i_Sheet ,Integer i_BeginRow ,Integer i_EndRow)
{
    PartitionMap<String ,RCell> v_Ret      = new TablePartition<String ,RCell>();
    Sheet                       v_Sheet    = i_Sheet;
    int                         v_BeginRow = 0;
    int                         v_EndRow   = 0;
    
    if ( i_BeginRow != null )
    {
        v_BeginRow = i_BeginRow.intValue();
        
        if ( v_BeginRow < 0 )
        {
            v_BeginRow = 0;
        }
    }
    
    if ( i_EndRow != null )
    {
        v_EndRow = i_EndRow.intValue();
    }
    else
    {
        v_EndRow = v_Sheet.getPhysicalNumberOfRows();
    }
    
    for (int v_RowNo=v_BeginRow; v_RowNo<=v_EndRow; v_RowNo++)
    {
        Row v_Row = v_Sheet.getRow(v_RowNo);
        if ( v_Row == null )
        {
            continue;
        }
        
        short v_CellCount = v_Row.getLastCellNum();
        
        for (int v_ColumnNo=0; v_ColumnNo<v_CellCount; v_ColumnNo++)
        {
            Cell v_Cell = v_Row.getCell(v_ColumnNo);
            if ( v_Cell == null )
            {
                continue;
            }
            
            if ( v_Cell.getCellTypeEnum() == CellType.STRING )
            {
                String v_Value = v_Cell.getStringCellValue();
                
                if ( !Help.isNull(v_Value) )
                {
                    RCell        v_RCell    = new RCell(v_RowNo ,v_ColumnNo);
                    List<String> v_Decimals = StringHelp.getString(v_Cell.getCellStyle().getDataFormatString() ,$Decimal);
                    if ( !Help.isNull(v_Decimals) )
                    {
                        v_RCell.setDecimal(v_Decimals.get(0).split("\\.")[1].length());
                    }
                    
                    v_Ret.putRow(v_Value.trim() ,v_RCell);
                }
            }
            else if ( v_Cell.getCellTypeEnum() == CellType.NUMERIC )
            {
                if ( HSSFDateUtil.isCellDateFormatted(v_Cell) ) 
                {
                    if ( v_Cell.getDateCellValue() != null )
                    {
                        v_Ret.putRow((new Date(v_Cell.getDateCellValue())).getFull() ,new RCell(v_RowNo ,v_ColumnNo));
                    }
                } 
                else 
                {
                    v_Ret.putRow(String.valueOf(v_Cell.getNumericCellValue()) ,new RCell(v_RowNo ,v_ColumnNo));
                }
            }
        }
    }
    
    return v_Ret;
}
 
開發者ID:HY-ZhengWei,項目名稱:hy.common.report,代碼行數:80,代碼來源:ExcelHelp.java


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