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:
Andrew C. Oliver 2002-10-01 20:40:29 +00:00
parent 7000fe4dfb
commit e0b73de5bf

View File

@ -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;
double d = cell.getNumericCellValue(); switch(format) {
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;
} }