Solved

apache poi  date format - xssf

Posted on 2014-02-07
5
1,272 Views
Last Modified: 2014-02-19
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
0
Comment
Question by:sniger
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

by:krakatoa
ID: 39843168
What do you mean "out of whack"? What does it look like after it ends up in Excel?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 400 total points
ID: 39843189
style.setDataFormat(df.getFormat("dd.MM.yyyy"));

Open in new window

I don't know this API, but, by the looks, getFormat gets a built-in format. afaics, there isn't such a built-in one:

http://poi.apache.org/apidocs/org/apache/poi/ss/usermodel/BuiltinFormats.html
0
 

Author Comment

by:sniger
ID: 39848624
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
0
 
LVL 16

Assisted Solution

by:krakatoa
krakatoa earned 100 total points
ID: 39848844
Let us know if you heeded CEHJ's comment first, if you please.

BTW, 'D' and 'd' are different you realise.
0
 

Author Comment

by:sniger
ID: 39870598
actually, it is not an issue, I had logic error and it did not set the format I expected
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now