From e191c1b553a363ce49f79c2419d6862fa89243b9 Mon Sep 17 00:00:00 2001 From: "Andrew C. Oliver" Date: Tue, 1 Oct 2002 20:40:29 +0000 Subject: [PATCH] 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 --- .../poi/hssf/usermodel/HSSFDateUtil.java | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFDateUtil.java b/src/java/org/apache/poi/hssf/usermodel/HSSFDateUtil.java index 9ab294f3fa..fb26a7d972 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFDateUtil.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFDateUtil.java @@ -143,19 +143,13 @@ public class HSSFDateUtil } /** - * 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. + * given a format ID this will check whether the format represents + * an internal date format or not. */ - 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(); - switch(i) { + public static boolean isInternalDateFormat(int format) { + boolean retval =false; + + switch(format) { // Internal Date Formats as described on page 427 in // Microsoft Excel Dev's Kit... case 0x0e: @@ -170,13 +164,31 @@ public class HSSFDateUtil case 0x2d: case 0x2e: case 0x2f: - bDate = true; + retval = true; break; default: - bDate = false; + retval = false; 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; } -- 2.39.5