Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-21-2008, 12:53 PM
Member
 
Join Date: Jun 2008
Posts: 1
muralimohanbikki is on a distinguished road
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?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Query resultset into Excel Sheet chandpuri Database 6 06-05-2008 04:08 PM
Save data from Excel sheet to servlet chandu.v Java Servlet 2 04-10-2008 03:51 PM
Regarding retrieval of sheet names from a excel workbook yuvaraj23 New To Java 0 03-11-2008 04:20 PM
How to set the AutoFilter to Excel Sheet with Wither POI or JXL lnarayana_boga Advanced Java 0 01-29-2008 11:05 AM
JExcel: Copy a cell content from one sheet to another sheet in the same workbook. ukbasak Advanced Java 0 08-02-2007 02:31 PM


All times are GMT +3. The time now is 11:03 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org