Link to home
Start Free TrialLog in
Avatar of sniger
sniger

asked on

apache poi date format - xssf

I set up a format for my cel:
  DataFormat df = wb.createDataFormat();

style = createBorderedStyle(wb);
        style.setAlignment(CellStyle.ALIGN_RIGHT);
        style.setFont(font1);
        style.setDataFormat(df.getFormat("dd.MM.yyyy"));
        styles.put("cell_pub_date", style);

Open in new window


before that I retrieve date from the database in the format cyymmdd, format it:

String year = "20" +  field.substring(1,3);
                        			String month  = field.substring(3,5);
                        			String day   = field.substring(5,7);		

          							SimpleDateFormat sf  = new SimpleDateFormat("dd.MM.yyyy");

                        			String date_s  = day + "." + month + "." + year;
                        			System.out.println(date_s);

                        			try {

										java.util.Date date = sf.parse(date_s);
										System.out.println(date.toString());     
										c.setCellValue(date);
										c.setCellStyle(styles.get("cell_pub_date"));
									}

	
									catch (Exception e)	 {

										System.out.println( );	
									}	

Open in new window



but the date is comletely out of whack in my excel spreadhseet
Avatar of krakatoa
krakatoa
Flag of United Kingdom of Great Britain and Northern Ireland image

What do you mean "out of whack"? What does it look like after it ends up in Excel?
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sniger
sniger

ASKER

krakatoa,

I changed the format to m/d/yy in my po style

In java se I assume it is       SimpleDateFormat sf  = new SimpleDateFormat("MM/dd/yyyy");


not for the date:    02/11/2013  I am getting in Excel:    5/29/94
                                 09/10/ 2010                                         3/9/14
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sniger

ASKER

actually, it is not an issue, I had logic error and it did not set the format I expected