• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Rendering Excel spreadsheet in JSP OR via CSV File Download

 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
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>
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic