you should now be able to check for date formats from the eventmodel
PR: Obtained from: Submitted by: Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352874 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7000fe4dfb
commit
e0b73de5bf
@ -143,19 +143,13 @@ public class HSSFDateUtil
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a cell contains a date
|
* given a format ID this will check whether the format represents
|
||||||
* Since dates are stored internally in Excel as double values
|
* an internal date format or not.
|
||||||
* we infer it is a date if it is formatted as such.
|
|
||||||
*/
|
*/
|
||||||
public static boolean isCellDateFormatted(HSSFCell cell) {
|
public static boolean isInternalDateFormat(int format) {
|
||||||
if (cell == null) return false;
|
boolean retval =false;
|
||||||
boolean bDate = false;
|
|
||||||
|
switch(format) {
|
||||||
double d = cell.getNumericCellValue();
|
|
||||||
if ( HSSFDateUtil.isValidExcelDate(d) ) {
|
|
||||||
HSSFCellStyle style = cell.getCellStyle();
|
|
||||||
int i = style.getDataFormat();
|
|
||||||
switch(i) {
|
|
||||||
// Internal Date Formats as described on page 427 in
|
// Internal Date Formats as described on page 427 in
|
||||||
// Microsoft Excel Dev's Kit...
|
// Microsoft Excel Dev's Kit...
|
||||||
case 0x0e:
|
case 0x0e:
|
||||||
@ -170,13 +164,31 @@ public class HSSFDateUtil
|
|||||||
case 0x2d:
|
case 0x2d:
|
||||||
case 0x2e:
|
case 0x2e:
|
||||||
case 0x2f:
|
case 0x2f:
|
||||||
bDate = true;
|
retval = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
bDate = false;
|
retval = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a cell contains a date
|
||||||
|
* Since dates are stored internally in Excel as double values
|
||||||
|
* we infer it is a date if it is formatted as such.
|
||||||
|
* @see #isInternalDateFormat(int)
|
||||||
|
*/
|
||||||
|
public static boolean isCellDateFormatted(HSSFCell cell) {
|
||||||
|
if (cell == null) return false;
|
||||||
|
boolean bDate = false;
|
||||||
|
|
||||||
|
double d = cell.getNumericCellValue();
|
||||||
|
if ( HSSFDateUtil.isValidExcelDate(d) ) {
|
||||||
|
HSSFCellStyle style = cell.getCellStyle();
|
||||||
|
int i = style.getDataFormat();
|
||||||
|
bDate = isInternalDateFormat(i);
|
||||||
}
|
}
|
||||||
return bDate;
|
return bDate;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user