First of all thanks for the previous help. What I want to do is the following. Is to collect information through a small program that can capture in Java and writes it to a file which I have done. Then to have this information passed to a preformatted excel spread sheet. In the spread sheet it reads this data that is written and displays it in different tables and graphs. Is this possible to automatically code or do I have to write to a csv file, from the csv file manually copy to an excel template? If anybody has come across a solution to my problem I would appreciate a steer in the right direction
2 Answers
Hey try ths code in servlet or in JSP. This will convert simple excel sheet on which you can do further operations..
response.setContentType("application/vnd.ms-excel");
PrintWriter out = response.getWriter();
try {
out.println("\tId \tName");
out.println("\t1\tabc");
out.println("\t2\txyz");
out.println("\t3\tpqr");
} finally {
out.close();
}
here ..
response.setContentType("application/vnd.ms-excel");
specify the excel sheet to be generated.. all "\t" separates new cell in the excel sheet.
On your requirement basis you can also change this code with database or any...
Comments
It's a duplicate of How to read and write excel file in java
you can use this API: http://poi.apache.org/
Or if you write one text file with tab separation between fields and save with (.XLS) extension, excel should read it. But off course the better solution is to use Apache POI HSSF.
Apache POIis the framework, which will be useful for you. More info: poi.apache.org