• Post Reply Bookmark Topic Watch Topic
  • New Topic

Rendering Excel spreadsheet in JSP OR via CSV File Download  RSS feed

Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
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.*" %>
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);
// Or do it on one line.
row.createCell((short)2).setCellValue("This is a string");
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");

Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about trying some JSP chart utilities.
See if the following article is of any use
Here is the opensource chart utility.
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!