I am using apache poi 3.8 to create an excel file. This excel file needs to contain some dates.
I am trying to write a date to the excel file with as format the excel type "date". But i always get a type "custom". I need to use the the type "date", so it will be localized based on the users settings.
I have tried the following:
Apache POI localized Date into Excel cell
But it doens't work.
This is the code that I have:
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.createSheet("new sheet");
XSSFDataFormat df = wb.createDataFormat();
CellStyle cs = wb.createCellStyle();
cs.setDataFormat(df.getFormat("d-mmm-yy"));
XSSFCell cell = sheet.createRow(0).createCell(0);
Calendar c = Calendar.getInstance();
c.set(2012,3-1,18);
cell.setCellValue( c.getTime() );
cell.setCellStyle(cs);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("c:\\temp\\dates-sworkbook.xlsx");
wb.write(fileOut);
fileOut.close();
Which format should I use?
Thanks