Hi,
I am writing a JSPDynpage and I have a requirement to generate and save an excel file when I click a URL link in the page. I created a URL component using HTMLB and in its event handler method I wrote the following logic to create the excel file.
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
HSSFRow row = sheet.createRow(0);
HSSFCell cell = row.createCell((short)0);
cell.setCellValue("User Id");
cell = row.createCell((short)1);
cell.setCellValue("First Name");
cell = row.createCell((short)2);
cell.setCellValue("Last Name");
for (int x = 1; x <= arrList.length; x++) {
// Create a row and put some cells in it. Rows are 0 based.
row = sheet.createRow(x);
for (int y = 0; y < 3; y++) {
cell = row.createCell((short)y);
cell.setCellValue(arrList[x-1][y]);
}
}
// Write the output to a file
try {
java.io.FileOutputStream fileOut = new java.io.FileOutputStream("D:/FirstExcel.xls");
wb.write(fileOut);
fileOut.close();
} catch (Exception e) {
e.printStackTrace();
}
In the above code i have hardcoded the excel file name and location but ideally I want a File Download Box to come up when i click the URL link in my JSPDynpage and then select the location to save my file.
Can any one please let me know how to do it.
Thanks & Regards,
Sudhir