Hi

I did a little bit of debugging with my example code and sample file which are 
attached
and this is what I found

for my code and sample data  this is what I found 
There seems to be a problem within StylesTable.readFrom

the instance variable doc holds the following data


<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main";>
  <numFmts count="2">
    <numFmt numFmtId="164" formatCode="m/d/yyyy;@"/>
    <numFmt numFmtId="165" formatCode="[$-F800]dddd\,\ mmmm\ dd\,\ yyyy"/>
  </numFmts>
  <fonts count="1">
    <font>
      <sz val="11"/>
      <color theme="1"/>
      <name val="Calibri"/>
      <family val="2"/>
      <scheme val="minor"/>
    </font>
  </fonts>
  <fills count="2">
    <fill>
      <patternFill patternType="none"/>
    </fill>
    <fill>
      <patternFill patternType="gray125"/>
    </fill>
  </fills>
  <borders count="1">
    <border>
      <left/>
      <right/>
      <top/>
      <bottom/>
      <diagonal/>
    </border>
  </borders>
  <cellStyleXfs count="1">
    <xf numFmtId="0" fontId="0" fillId="0" borderId="0"/>
  </cellStyleXfs>
  <cellXfs count="4">
    <xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/>
    <xf numFmtId="164" fontId="0" fillId="0" borderId="0" xfId="0" 
applyNumberFormat="1"/>
    <xf numFmtId="14" fontId="0" fillId="0" borderId="0" xfId="0" 
applyNumberFormat="1"/>
    <xf numFmtId="165" fontId="0" fillId="0" borderId="0" xfId="0" 
applyNumberFormat="1"/>
  </cellXfs>
  <cellStyles count="1">
    <cellStyle name="Normal" xfId="0" builtinId="0"/>
  </cellStyles>
  <dxfs count="0"/>
  <tableStyles count="0" defaultTableStyle="TableStyleMedium9" 
defaultPivotStyle="PivotStyleLight16"/>
</styleSheet>

Clearly the numFmts array contains two elements whereas the cellXfs contains 4 
elements.So when StylesTable.getStyleAt is called with index 2 (row 2,cell1) 
which calls the XSSFStyle constructor with this idx,
the numFmtId which is pulled out of the map and stored in cellXf variable in 
XSSFCellStyle is 
    <xf numFmtId="14" fontId="0" fillId="0" borderId="0" xfId="0" 
applyNumberFormat="1"/>

So later when this numFmtId 14 is used ofcourse the format is returned null.So 
I think this a bug,
but why does the schema put xf with numfmtId 14 in there?


anyone seen this before.I mean is anyone reading excel files with dates and 
putting them into text files?

Regards
A




-----Original Message-----
From: Avinash Kewalramani [mailto:[email protected]] 
Sent: Tuesday, December 30, 2008 9:46 AM
To: POI Users List
Subject: RE: Cell format for dates : CELL_TYPE_NUMERIC

Hi

I forgot to mention clearly that this was not working only for XSSF 
documents.All HSSF documents behave the same way they used to before migration. 

I would really appreciate any responses.

Regards
A

-----Original Message-----
From: Avinash Kewalramani [mailto:[email protected]] 
Sent: Monday, December 29, 2008 6:06 PM
To: POI Users List
Subject: Cell format for dates : CELL_TYPE_NUMERIC

Hi

I had some code which was reading HSSF documents and converting the cell values 
to a delimited text file.pretty straightforward.

I changed that code to ss model so that it could read both hssf and xssf. For 
me most of it is working except for one small exceptional case

I have a file with different date formats and one of them is


4/1/2007 format is date and type is  *3/04/2001 (case1)
The same data is repeated in the file with with format as  date and type is 
3/14/2001 works fine(case2)

Here is the code snippet

Cell cell;
switch (cell.getCellType()) {
            case Cell.CELL_TYPE_NUMERIC:
                                String formatStr = 
cell.getCellStyle().getDataFormatString();
                              if (DateToString.isDateType(formatStr)) {
                                    ..date logic here....
                              }else{
                                    ...non date logic here...
                              }


out of the above two data cases case 1 does not work but case 2 works just 
fine.I debugged and seems like
the problem is the formatStr is being returned as null and it does not happen 
for the HSSF type of for XSSF with the other data type(case2).hence it does not 
enter the if loop where all the date logic is

is this a bug in POI which has been documented or is this a bug in the 
underlying open xml schema implementation
or am i really doing something weird here?

anyone else seen this. any pointers/comments appreciated.

Regards
Avi



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Attachment: date_test.xlsx
Description: date_test.xlsx

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to