Results 1 to 1 of 1
- 06-21-2008, 10:53 AM #1
Member
- Join Date
- Jun 2008
- Posts
- 1
- Rep Power
- 0
Not able to download excel sheet from client mechine using Struts and JExcel
Hi, I am using Struts and JExcel to generate excel sheet and download. In server I am able to save and download, but in client mechine I am not able to download and save the excel file.Following is the code snippet in action class
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.ArrayList;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.log4j.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.biff.*;
import jxl.write.Label;
import jxl.write.BoldStyle;
import jxl.write.Font;
import jxl.write.Alignment;
import jxl.write.VerticalAlignment;
import jxl.write.WritableFont;
import jxl.write.WritableCell;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WritableCellFormat;
public class ExportToExcelAction extends Action{
Logger loagger = Logger.getLogger("com.rtrade");
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception{
ArrayList searchResults = new ArrayList();
//
--------------------------------------------------------------------------------
//---------
HttpSession session = request.getSession();
Calendar d = new GregorianCalendar();
String filename = d.get(Calendar.DAY_OF_MONTH) + ""+ d.get(Calendar.MONTH) + "" + d.get(Calendar.YEAR) + "_"+ userName;
//String logName = "LogDetails_"userName".log";
response.setContentType("application/vnd.ms-excel");
//response.setHeader("Content-Disposition", "attachment; filename="+filename);
WritableFont font = new WritableFont(WritableFont.ARIAL,10,WritableFont.BO LD);
WritableCellFormat format = new WritableCellFormat(font);
format.setWrap(true);
format.setAlignment(Alignment.CENTRE);
format.setVerticalAlignment(VerticalAlignment.CENT RE);
WritableWorkbook workBook = Workbook.createWorkbook(response.getOutputStream() );
if(actionType.equalsIgnoreCase("backtobranch")){
String reportName = "BackToBranch_"+filename;
response.setHeader("Content-Disposition", "attachment; filename="+reportName);
branchDO = new BackToBranchDO();
searchResults = (ArrayList)session.getAttribute("RESULTS");
int recCount = searchResults.size();
WritableSheet sheet = workBook.createSheet("Back to Branch", 0);
sheet.addCell(new Label(0,0,"ApplicatioId",format));
sheet.addCell(new Label(1,0,"File No.",format));
sheet.addCell(new Label(2,0,"Cheque Status",format));
sheet.addCell(new Label(3,0,"Reason",format));
sheet.addCell(new Label(4,0,"Additional Reason",format));
sheet.addCell(new Label(5,0,"Inwarded Date",format));
sheet.addCell(new Label(6,0,"Scrutiny Date",format));
sheet.addCell(new Label(7,0,"Branch Name",format));
sheet.addCell(new Label(8,0,"Courier Number",format));
sheet.addCell(new Label(9,0,"Courier Name",format));
sheet.addCell(new Label(10,0,"Courier Date",format));
for(int i=0;i<recCount; i++){
branchDO = (BackToBranchDO)searchResults.get(i);
sheet.addCell(new Label(0,i+1,branchDO.getApplicationId()));
sheet.addCell(new Label(1,i+1,branchDO.getFileNo()));
sheet.addCell(new Label(2,i+1,branchDO.getChequeStatus()));
sheet.addCell(new Label(3,i+1,branchDO.getReason()));
sheet.addCell(new Label(4,i+1,branchDO.getAdditionalReason()));
sheet.addCell(new Label(5,i+1,branchDO.getInwardDate()));
sheet.addCell(new Label(6,i+1,branchDO.getStatusDate()));
sheet.addCell(new Label(7,i+1,branchDO.getBranchName()));
sheet.addCell(new Label(8,i+1,branchDO.getCourierNo()));
sheet.addCell(new Label(9,i+1,branchDO.getCourierName()));
sheet.addCell(new Label(10,i+1,branchDO.getCourierDate()));
}
Could any body help to my problem?
Similar Threads
-
SQL Query resultset into Excel Sheet
By chandpuri in forum JDBCReplies: 8Last Post: 01-24-2011, 06:53 PM -
Save data from Excel sheet to servlet
By chandu.v in forum Java ServletReplies: 2Last Post: 04-10-2008, 01:51 PM -
Regarding retrieval of sheet names from a excel workbook
By yuvaraj23 in forum New To JavaReplies: 0Last Post: 03-11-2008, 02:20 PM -
How to set the AutoFilter to Excel Sheet with Wither POI or JXL
By lnarayana_boga in forum Advanced JavaReplies: 0Last Post: 01-29-2008, 09:05 AM -
JExcel: Copy a cell content from one sheet to another sheet in the same workbook.
By ukbasak in forum Advanced JavaReplies: 0Last Post: 08-02-2007, 12:31 PM


LinkBack URL
About LinkBacks

Bookmarks