Question

So I am creating a csv report within my java code and using excel to open the exported csv file. One of the column is a date which I am formatting within my code to be mm/dd/yyyy hh:mm:ss. This comes out as 02/10/2014 3:38:00 PM. Which is exactly how I want it. However the columns in the excel sheet display this as 02/10/2014 3:38. When I click on a cell in the excel sheet, it does display the full date at the top but I want it to display on the column itself so that it is easier to print. It doesn't seem like a column width issue since I have changed the column width but the full date still won't appear. I am however able to achieve it by changing the number format cells setting to custom. Is this something that can be done within java itself? Let me know if you need more information. Thanks!

Was it helpful?

Solution

Comma-separated values (CSV) is stores tabular data in plain-text format. To give Excel an instruction how to format a particular column you would need to user Excel format. In order to achieve it, you may use a Java library to export data in Excel format. One example of such a library is Apache POI - the Java API for Microsoft Documents (http://poi.apache.org/).

In addition, to work better with CSV files in Excel use import from text feature. This is a wizard you can specify the import settings, including column formats, width of the fields etc.

I hope it helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top