Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Saving excel workbook using apache POI HSSF

843785Jan 9 2009 — edited Jan 9 2009
Hi

I have written a simple code to generate a excel workbook from servlet using Apache POI.
But here I have to hardcode the excel name and path to be saved.
<%@ page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@ page import="org.apache.poi.poifs.filesystem.POIFSFileSystem"%>
<%@ page contentType="application/vnd.ms-excel" %>
<%@ page import="java.io.*" %>
<%
try{
   POIFSFileSystem fs=new POIFSFileSystem(new FileInputStream
("c:\\excel\\rajesh1.xls"));
    HSSFWorkbook wb=new HSSFWorkbook(fs);
    FileOutputStream fileOut = new FileOutputStream(
"c:\\excel\\readingWriting.xls");
    wb.write(fileOut);
    fileOut.close();
      out.println("Your excel file has been generated");
            
        } catch ( Exception ex ) {       
        }
%>
But I have seen in web sites that if u wish to download an excel sheet, then on clicking on download link,
we get a pop-up which asks to save, view or cancel action.
If we choose save, a dialogue box appears where we can select path and give a name for our file.

How is this possible in my code above
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 6 2009
Added on Jan 9 2009
2 comments
670 views