Nick Burch wrote:
On Tue, 19 May 2009, Chris Lott wrote:
Does DateUtil provide any assistance for XSSF sheets? Do I need to use XSSFDataFormat class? How else can I address this problem?

org.apache.poi.ss.usermodel.DataFormatter might work for you. That's basically what FormatTrackingHSSFListener uses internally

That "might" in your sentence leaves much wiggle room :-) :-) But thanks for the clue, I pursued it. Here is part of the styles.xml file from Dale Monti's post:

<pre>

 &lt;cellStyleXfs count="1"&gt;
  &lt;xf numFmtId="0" fontId="0" fillId="0" borderId="0" /&gt;
  &lt;/cellStyleXfs&gt;
 &lt;cellXfs count="2"&gt;
  &lt;xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0" /&gt;
&lt;xf numFmtId="14" fontId="0" fillId="0" borderId="0" xfId="0" applyNumberFormat="1" /&gt;
  &lt;/cellXfs&gt;
 &lt;cellStyles count="1"&gt;
  &lt;cellStyle name="Normal" xfId="0" builtinId="0" /&gt;
  &lt;/cellStyles&gt;

</pre>

The entry with numFmtId = 14 seems to be the style at index 1 that is referenced by the cell with the date value. Is this where the magic of formatting dates is buried? I sure don't see any local, custom format string in that styles table entry.

The evidence I see indicates that number format index 14 is a date-only, number format index 20 is a time-only, and number format index 22 is a datetime. Is that just accidental, or are those well-known numbers?

Anyhow, starting with the number format index of 14 that I obtained from XSSFCellStyle#getDataFormat, and the null data format string returned by XSSFCellStyle#getDataFormatString(), I tried calling DataFormatter#formatRawCellValue() passing it the double, short number format index, and null format string. Judging from the null-pointer exceptions I'm seeing, the formatRawCellValue() method needs a non-null format string. Here's a SWAG. Perhaps well-known default formats exist for date-only, time-only, and datetime values, and I can fetch them somehow?

chris...

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

Reply via email to