本文整理汇总了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() + "]");
}
示例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;
}
示例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;
}
示例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;
}
示例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");
}
示例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();
}
示例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());
}
示例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;
}