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);

              }

...

Reply via email to