Meaningless Drivel is fun!*
The moose likes JSP and the fly likes Rendering Excel spreadsheet in JSP OR via CSV File Download Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Rendering Excel spreadsheet in JSP OR via CSV File Download" Watch "Rendering Excel spreadsheet in JSP OR via CSV File Download" New topic
Author

Rendering Excel spreadsheet in JSP OR via CSV File Download

Gabriel Fox
Ranch Hand

Joined: Oct 17, 2001
Posts: 170
Hello guys, i intend to implement the following in my JSP.
1.Populate the screen after running a query with
say, three fields -- X, Y , Z or more
2.Sum the three columns and display at bottom
3.Provide a link on screen, when user clicks on this link i want to download the results on screen as a CSV file
4.Then open CSV in EXCEL as a graph(e.g. pie,bar chart etc), depending the most suitable chart for
Screen results.
OR
Display an excel spreadsheet directly on browser,the user can then use spreadsheet to create chart on browser.
Using Jakarta POI / HSSF , i was able to write the excel file to my hard drive i.e. C:\oc4j\j2ee\home\abc.xsl
NOTE : I am using Oracle Container for J2EE (OC4J)

But, i think the right implementation will be displaying the Excel on Screen so the user can use the excel chart wizard to produce the chart on the screen(browser). Is this possible?
Because if say, a thousand users are using the application , how do they access their individual excel spreadsheet on the server without file mismatch /issues.
Please, your ideas/codes will be appreciated.
This is what i am doing in my TestJSP.jsp at the moment :
<%@page contentType="application/vnd.ms-excel" %>
<%@page import="org.apache.poi.hssf.usermodel.*,java.io.*" %>
<html>
<body>
<%
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
// Create a row and put some cells in it. Rows are 0 based.
HSSFRow row = sheet.createRow((short)0);
// Create a cell and put a value in it.
HSSFCell cell = row.createCell((short)0);
cell.setCellValue(1);
// Or do it on one line.
row.createCell((short)1).setCellValue(1.2);
row.createCell((short)2).setCellValue("This is a string");
row.createCell((short)3).setCellValue(true);
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();

%>
</form>
</body>
</html>
sampy jagan
Ranch Hand

Joined: Sep 17, 2002
Posts: 34
How about trying some JSP chart utilities.
See if the following article is of any use
http://www.javaworld.com/javaworld/jw-12-2002/jw-1227-opensourceprofile.html
Here is the opensource chart utility.
https://sourceforge.net/projects/jfreechart
If you are trying to generate Excel file in the server for each request and provide a link for the same, try assosiating their names with session id so as to them unique for each user. Also you may have to think of writing a Scheduler to clean up the numerous files you generated.
Regards
jagan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Rendering Excel spreadsheet in JSP OR via CSV File Download