Package org.apache.poi.ss.util
Class DateFormatConverter
- java.lang.Object
-
- org.apache.poi.ss.util.DateFormatConverter
-
public final class DateFormatConverter extends Object
Convert java DateFormat patterns into Excel custom number formats. For example, to format a date in excel using the "dd MMMM, yyyy" pattern and Japanese locale, use the following code:
TODO Generalise this for all Excel format strings// returns "[$-0411]dd MMMM, yyyy;@" where the [$-0411] prefix tells Excel to use the Japanese locale String excelFormatPattern = DateFormatConverter.convert(Locale.JAPANESE, "dd MMMM, yyyy"); CellStyle cellStyle = workbook.createCellStyle(); DataFormat poiFormat = workbook.createDataFormat(); cellStyle.setDataFormat(poiFormat.getFormat(excelFormatPattern)); cell.setCellValue(new Date()); cell.setCellStyle(cellStyle); // formats date as '2012年3月17日'
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDateFormatConverter.DateFormatTokenizer
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringconvert(Locale locale, String format)static Stringconvert(Locale locale, DateFormat df)static StringgetJavaDatePattern(int style, Locale locale)static StringgetJavaDateTimePattern(int style, Locale locale)static StringgetJavaTimePattern(int style, Locale locale)static StringgetPrefixForLocale(Locale locale)
-
-
-
Method Detail
-
convert
public static String convert(Locale locale, DateFormat df)
-
-