Bug 42630 - Excel : isInternalDateFormat
Summary: Excel : isInternalDateFormat
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: unspecified
Hardware: Other other
: P1 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-06-10 23:45 UTC by Sankar
Modified: 2007-06-17 08:54 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sankar 2007-06-10 23:45:20 UTC
I am using Microsoft excel 2003. I have a date formated cell in the
sheet(14/06/1941 ENGLISH UK format). When i debugged the value of the
HSSFCellStyle.getDataFormat is 198 . But in the method isInternalDateFormat it
fails. But if i add 198 to the check list, it succeeds.

 /**
  * given a format ID this will check whether the format represents
  * an internal date format or not. 
  */
 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:
             case 0x0f:
             case 0x10:
             case 0x11:
             case 0x12:
             case 0x13:
             case 0x14:
             case 0x15:
             case 0x16:
             case 0x2d:
             case 0x2e:
             case 0x2f:
             case 198:
                 retval = true;
                 break;
                 
             default:
                 retval = false;
                 break;
         }
    return retval;
 }
Comment 1 Yegor Kozlov 2007-06-13 02:29:03 UTC
Sankar, please play nice.
Setting the priority to blocker may have an opposite effect - you will be ignored.

If you want to help in fixing this bug, please attach a sample xls file and a
unit test to demonstrate what's wrong. 

Regards,
Yegor
Comment 2 Nick Burch 2007-06-17 08:54:08 UTC
I'm pretty sure that a format with an ID as high as 198 isn't an internal
(excel) date format. Instead, at the file format level, it's almost certainly a
custom date format (even if it might now be a standard one in an excel dropdown)

I've added a new method to HSSFDateUtil of isADateFormat. You pass this both the
format ID, and the format string. If it's an internal date format, it'll return
true. If not, it looks at the format string, and if that's only made up of date
formatting characters, returns true.

Try giving that a whirl, it's in svn.