Hi,

Is there a function (or does anyone have one that they are prepared to share) for converting Java data formats into Excel?

I need to be able to convert DEFAULT, SHORT, MEDIUM, LONG to formats that work in Excel for any locale.
At the moment I am doing this:
private void dumpSingleDateFormat( Row row, Locale locale, int style, int colnum, Date date ) {

        DateFormat dateFormat = DateFormat.getDateInstance(style, locale);

        Cell cell = row.createCell(colnum);
        cell.setCellValue(date);
CellStyle cellStyle = row.getSheet().getWorkbook().createCellStyle();

        // Note that this cast may be Sun-JVM specific
String dateFormatPattern = ((SimpleDateFormat)dateFormat).toLocalizedPattern();

DataFormat poiFormat = row.getSheet().getWorkbook().createDataFormat();
        cellStyle.setDataFormat(poiFormat.getFormat(dateFormatPattern));

        cell.setCellStyle(cellStyle);
    }
for every locale and DateFormatter style.

This works for most locales, but for some the pattern used by Java differs from that used by Excel.
So I want to run the pattern through a function to make it work.

Q1. Does anyone have such a function that they can share?
Q2. If not, do you want a copy of whatever I end up with?
Not being a localization expert, if I write the function I can't guarantee that the output is correct, but at least it won't make Excel barf.

Jim

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

Reply via email to