Solved

apache poi  date format - xssf

Posted on 2014-02-07
5
1,411 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 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.
Suggested Courses

627 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