You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Alan Bowsher <al...@supplydynamics.com> on 2011/08/17 00:47:41 UTC
XSSF SAX parser and dates
I've used the XLSX2CSV example to get a grip on how to parse an xlsx
file using SAX. Thanks for the great example, it saved me a lot of
time!
I pulled a bit of code out of the DateUtil class to be able to check for
whether the cell is a Date, and to get the value back (see below).
My only question is, using the SAX parser, how do I tell if the workbook
is using the 1904-indexed dates? Or is that so unlikely to be used that
I shouldn't worry about it?
Well, one other question: are there any known gotchas with this example?
I want to use it to base my parser off of, and the only thing I saw on
the mailing list was the issue with empty cells.
Thanks!
// My added method
public static boolean isCellDateFormatted(double value, short
formatIndex, String formatString) {
boolean isDate = false;
if ( DateUtil.isValidExcelDate(value) ) {
isDate = DateUtil.isADateFormat(formatIndex, formatString);
}
return isDate;
}
// Handling the date, in the context of the existing endElement()
method:
case NUMBER:
String n = value.toString();
if (this.formatString != null) {
double numberValue = Double.parseDouble(n);
boolean isDate = isCellDateFormatted(numberValue,
this.formatIndex, this.formatString);
if (isDate) {
//boolean date1904 =
getSheet().getWorkbook().isDate1904();
java.util.Date myDate =
DateUtil.getJavaDate(numberValue);
}
...
RE: XSSF SAX parser and dates
Posted by Nick Burch <ni...@alfresco.com>.
On Wed, 17 Aug 2011, Alan Bowsher wrote:
> Yeah, but I'm using the SAX parser.... I don't have an XSSFWorkbook
> (unless there's some way to get to it that I don't understand).
You want to look at the code of how XSSFWorkbook does it, and do something
similar.
Nick
> -----Original Message-----
> From: Nick Burch [mailto:nick.burch@alfresco.com]
> Sent: Wednesday, August 17, 2011 7:31 AM
> To: POI Users List
> Subject: Re: XSSF SAX parser and dates
>
> On Tue, 16 Aug 2011, Alan Bowsher wrote:
>> My only question is, using the SAX parser, how do I tell if the
>> workbook is using the 1904-indexed dates? Or is that so unlikely to
>> be used that I shouldn't worry about it?
>
> The 1900 vs 1904 date information is stored on the workbook. If you look
> at XSSFWorkbook you can see how to check for it - isDate1904()
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org For additional
> commands, e-mail: user-help@poi.apache.org
>
>
> ________________________________________________________________________
> _____
> Scanned by IBM Email Security Management Services powered by
> MessageLabs. For more information please visit
> http://www-935.ibm.com/services/us/index.wss/offerfamily/iss/a1026954
> ________________________________________________________________________
> _____
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
RE: XSSF SAX parser and dates
Posted by Alan Bowsher <al...@supplydynamics.com>.
Yeah, but I'm using the SAX parser.... I don't have an XSSFWorkbook
(unless there's some way to get to it that I don't understand).
-----Original Message-----
From: Nick Burch [mailto:nick.burch@alfresco.com]
Sent: Wednesday, August 17, 2011 7:31 AM
To: POI Users List
Subject: Re: XSSF SAX parser and dates
On Tue, 16 Aug 2011, Alan Bowsher wrote:
> My only question is, using the SAX parser, how do I tell if the
> workbook is using the 1904-indexed dates? Or is that so unlikely to
> be used that I shouldn't worry about it?
The 1900 vs 1904 date information is stored on the workbook. If you look
at XSSFWorkbook you can see how to check for it - isDate1904()
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org For additional
commands, e-mail: user-help@poi.apache.org
________________________________________________________________________
_____
Scanned by IBM Email Security Management Services powered by
MessageLabs. For more information please visit
http://www-935.ibm.com/services/us/index.wss/offerfamily/iss/a1026954
________________________________________________________________________
_____
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: XSSF SAX parser and dates
Posted by Nick Burch <ni...@alfresco.com>.
On Tue, 16 Aug 2011, Alan Bowsher wrote:
> My only question is, using the SAX parser, how do I tell if the workbook
> is using the 1904-indexed dates? Or is that so unlikely to be used that
> I shouldn't worry about it?
The 1900 vs 1904 date information is stored on the workbook. If you look
at XSSFWorkbook you can see how to check for it - isDate1904()
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org