GeeCON Prague 2014*
The moose likes Servlets and the fly likes display csv file as an excel in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "display csv file as an excel in java" Watch "display csv file as an excel in java" New topic
Author

display csv file as an excel in java

Dhivya Krishnan
Ranch Hand

Joined: Apr 27, 2010
Posts: 41
Hi.,

On a button click,I want to read the contents of a csv file inside a directory and open the same contents as an excel file.
I am able to read the contents in a csv file, but can some one help me in displaying it in an excel format.?
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

This might help

http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/ss/examples/


Swastik
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42061
    
  64
Dhivya Krishnan wrote:displaying it in an excel format.?

What does that mean? There are any number of ways of displaying a spreadsheet, including mimicking the way Excel would. Are you asking how to do that in a Java app? If so, POI plays no role in that. If you meant something else, please elaborate.


Ping & DNS - my free Android networking tools app
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

How about a simple JTable?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Dhivya Krishnan
Ranch Hand

Joined: Apr 27, 2010
Posts: 41
Thanks for the link swastik., but that was not what i was searching for.
I have to read a csv file from some location for a particular date and its contents must be displayed to the user. This must happen on a button click. The contents must be displayed in an excel sheet.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

Do you mean it's a web application?
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

More over your query is not very clear. Even if its a standalone java app, do you wish to display the data just in excel format(i.e just a tabular representation), if so as suggested in one of the above posts JTable should be good enough, and if you wish to display the data in excel sheet itself, you probably need POI, and you should get some help regarding this from the link I have referred.
Dhivya Krishnan
Ranch Hand

Joined: Apr 27, 2010
Posts: 41
Swastik,since i am new to this concept i am not able to explain it clearly. Let me try it once again.
My requirement is i need to open an excel file on a button click., the data to this excel file must come a .csv file.
In the link which you gave., it is the other way converting excel file to .csv.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

Dhivya,
Button click on a desktop app or web app? I pretend this to be a desktop app, and if that is the case if you look at timesheet demo example, they are using String arrays to create the values in excel sheet, in your case only difference is instead of string array you have the data from a csv file.
Dhivya Krishnan
Ranch Hand

Joined: Apr 27, 2010
Posts: 41
Its a web application
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

Ok, so the scenario is somewhat like this, correct me if I am wrong. User gets a web page. He/she clicks on a button, request goes to server. At the server side you open a csv file file, process it and send the contents back to the client, which is displayed in client's browser in excel sheet.
Dhivya Krishnan
Ranch Hand

Joined: Apr 27, 2010
Posts: 41
yes you are correct..
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

This has nothing to do with Swing, AWT, SWT or JFace.

You're going to need a servlet that outputs the Excel file, using the right content type and disposition. You call this servlet from your button. If all is set up correctly you will then get a popup asking the user to open or save the file.

I'll move this thread to our Servlets forum.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1477
    
    6

So, how far have you proceeded with the code?
Dhivya Krishnan
Ranch Hand

Joined: Apr 27, 2010
Posts: 41
I am able to read the csv file data., i want to know as how to add it to an excel.
Dhivya Krishnan
Ranch Hand

Joined: Apr 27, 2010
Posts: 41
Hi I am able to add it to an excel also now.. Now just need to work on displaying the excel.
Anyways thanks swastik for guiding.
 
GeeCON Prague 2014
 
subject: display csv file as an excel in java