开发者

How to convert a string to Date and then add it to excel using jexcel api

I am currently reading a CSV file. I have to extract the dates from it and add them to excel file in dd-MM-yy format. I am faced with two problems.

  1. I am using String.split(delim) where, delim="[,]". I am getting the date in yyyy-MM-dd format.
  2. I am not able to convert the string into a da开发者_StackOverflowte format and then add them to excel file. I tried using DateFormat but error says Dateformat is abstract.

Here is the code

dtformat=new SimpleDateFormat("dd-MM-yy");
datenow=dtformat.parse(stringDate);//datenow is what i want to add to add.
datecell=new DateTime(tokenNumber, lineNumber, datenow);
sheet.addCell(datecell);

When I open the excel file, I get wild values.

Please help.Thanks in advance


Google is your friend.

To parse date:

DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date date = (Date)formatter.parse("2011 02 07");

To write date:

DateFormat customDateFormat = new DateFormat ("dd-MM-yy"); 
WritableCellFormat dateFormat = new WritableCellFormat (customDateFormat); 
sheet.addCell(new DateTime(/* date */, dateFormat)); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜