Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

apache poi  date format - xssf

Posted on 2014-02-07
5
Medium Priority
?
1,487 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1600 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 400 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

715 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