I solved excel file download from jsp or javabean
first jexcel api download
i used the jexcel api
here sample ; using jexcel api
This code is servlet
==================================================================
SaleAgent sa = null;
public void init(ServletConfig config) throws ServletException {
super.init(config);
// get Sale List DB Agent Class
// you are modify
sa = new SaleAgent();
public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException {
res.setContentType("application/vnd.ms-excel");
res.setHeader("content-disposition", "attachment; filename=datesale.xls");
// to get Sale List Parameter
// you are modify
String biz_id = req.getParameter("biz_id");
String begindate = req.getParameter("begindate");
String enddate = req.getParameter("enddate");
// send parameter , set Parameter to get Data List from Database
// you are modify
sa.processDaySale(biz_id, enddate);
ServletOutputStream out = res.getOutputStream();
try {
WritableWorkbook workbook = Workbook.createWorkbook(out);
WritableSheet sheet = workbook.createSheet("datesale", 0);
// head cell
WritableCellFormat cf = new WritableCellFormat();
cf.setAlignment(Alignment.CENTRE);
cf.setBackground(Colour.LIGHT_GREEN);
cf.setWrap(true);
// data cell
WritableCellFormat cf2 = new WritableCellFormat();
cf2.setAlignment(Alignment.CENTRE);
cf2.setWrap(true);
// total cell
WritableCellFormat cf3 = new WritableCellFormat();
cf3.setAlignment(Alignment.CENTRE);
cf3.setBackground(Colour.LIME);
cf3.setWrap(true);
// etc
WritableCellFormat cf4 = new WritableCellFormat();
cf4.setBackground(Colour.LIME);
cf4.setWrap(true);
// column width setting
sheet.setColumnView(0, 10);
sheet.setColumnView(1, 15);
sheet.setColumnView(2, 15);
sheet.setColumnView(3, 15);
sheet.setColumnView(4, 15);
sheet.setColumnView(5, 15);
sheet.setColumnView(6, 15);
sheet.setColumnView(7, 15);
// head row setting
Label label = new Label(0, 0, "NO.", cf);
sheet.addCell(label);
label = new Label(1, 0, "sale_date", cf);
sheet.addCell(label);
label = new Label(2, 0, "week", cf);
sheet.addCell(label);
label = new Label(3, 0, "total_sale", cf);
sheet.addCell(label);
label = new Label(4, 0, "net_sale", cf);
sheet.addCell(label);
label = new Label(5, 0, "cash", cf);
sheet.addCell(label);
label = new Label(6, 0, "card", cf);
sheet.addCell(label);
label = new Label(7, 0, "merch_bond", cf);
sheet.addCell(label);
// data row setting
int t_total = 0;
int t_net = 0;
Number number = null;
int maxRow = sa.getCount();
for(int i = 0; i < maxRow; i++) {
int t_sales = sa.getTotal_Sales_Price(i);
int n_sales = sa.getTotal_Sales_Price(i) - sa.getTotal_Dc_Price(i);
number = new Number(0, i+1, i + 1, cf2);
sheet.addCell(number);
label = new Label(1, i+1, sa.getSale_Time(i), cf2);
sheet.addCell(label);
number = new Number(2, i+1, t_sales);
sheet.addCell(number);
number = new Number(3, i+1, sa.getTotal_Dc_Price(i));
sheet.addCell(number);
number = new Number(4, i+1, n_sales);
sheet.addCell(number);
number = new Number(5, i+1, sa.getCash(i));
sheet.addCell(number);
number = new Number(6, i+1, sa.getCredit_Card(i));
sheet.addCell(number);
number = new Number(7, i+1, sa.getMerch_bond(i));
sheet.addCell(number);
t_total = t_total + t_sales;
t_net = t_net + n_sales;
// total row setting
label = new Label(0, maxRow + 2, "", cf4);
sheet.addCell(label);
label = new Label(1, maxRow + 2, "Total : ", cf3);
sheet.addCell(label);
number = new Number(2, maxRow + 2, t_total, cf4);
sheet.addCell(number);
label = new Label(3, maxRow + 2, "", cf4);
sheet.addCell(label);
number = new Number(4, maxRow + 2, t_net, cf4);
sheet.addCell(number);
label = new Label(5, maxRow + 2, "", cf4);
sheet.addCell(label);
label = new Label(6, maxRow + 2, "", cf4);
sheet.addCell(label);
label = new Label(7, maxRow + 2, "", cf4);
sheet.addCell(label);
workbook.write();
workbook.close();
} catch(JXLException e) {
e.printStackTrace();
humm
may be servlet link's target have to hidden frame
i don't know correctly reason...
Similar Messages
-
Filename on file download from jsp
This may help:
----- Original Message -----
From: "Erik Lindquist" <[email protected]>
Newsgroups: weblogic.developer.interest.jsp
Sent: Wednesday, June 28, 2000 6:20 PM
Subject: How to dynamically display images in JSPs
> This took a little while to figure out so I thought I'd share. After
> doing some research I was led to the following approach on how to load
> images from an Oracle database into a JSP:
>
> The "main" JSP:
>
> <HTML>
> <head>
> <title>Image Test</title>
> </head>
> <body>
> <center>
> hello
> <P>
> <img border=0 src="getImage.jsp?filename=2cents.GIF">
> <P>
> <img border=0 src="getImage.jsp?filename=dollar.gif">
> <P>
> world
> </body>
> </HTML>
>
>
> And this is the image getter:
>
> <% try {
> response.setContentType("image/gif");
> String filename = (String) request.getParameter("filename");
> java.sql.Connection conn =
> java.sql.DriverManager.getConnection("jdbc:weblogic:pool:orapool"); //
> connect to db
> java.sql.Statement stmt = conn.createStatement();
> String sql = "select image from testimage where filename = '" +
> filename + "'";
> java.sql.ResultSet rs = stmt.executeQuery(sql);
> if (rs.next()) {
> byte [] image = rs.getBytes(1);
> java.io.OutputStream os = response.getOutputStream();
> os.write(image);
> os.flush();
> os.close();
> }
> conn.close();
> }
> catch (Exception x) { System.out.println(x); }
> %>
>
>
> The thing to note is that there are no <%@ page import="..." %> or <%@
> page contentType="..." %> tags - just the single scriptlet. It
> seems that for every "<%@" the weblogic compiler sees it puts
> out.print("\r\n"); statements in the generated java source.(???) I
> don't know much about how browsers work but I think that once it sees
> flat ascii come at it it treats everything that follows as text/plain
> which is incorrect for the binary stream that's being sent. Another
> work around was to set out = null; but that's kind of ugly and might
> produce server errors. The real fix is to write a bean to handle images
> which I'll work on next (does anybody have any hints on how to do
> that?)
Cameron Purdy
[email protected]
http://www.tangosol.com
WebLogic Consulting Available
"Ramesh" <[email protected]> wrote in message
news:[email protected]...
>
> Hi,
>
> Even I could download the files with this technique, I couldn't open the
file downloaded. It seems the file is getting currepted during tranfer.. Can
u help me in this regard please?
>
> Thank u
> Ramesh
>
> [email protected] (Anders B. Jensen) wrote:
> >In an Web-application written in Java Server Pages it should be possible
> >for the user to download data from the web-server. The data will never
> >exist as a file on the web-server, only in the PrintWriter object, out.
> >To force the Internet Explorer (IE) to show the download dialog window
> >the Contenttype of the HTTP-header have been set to "html/transfer". The
> >question is:
> >
> >Is it possible to set the filename appearing in the download dialog
> >appearing on the client?
> >
> >
> >Below is a listing of the source-code:
> >
> ><%@ page extends="com.beasys.portal.admin.PortalJspBase"%>
> ><jsp:useBean id="download" scope="session" class="dk.lec.DownloadData" />
> >
> ><%
> > String tmpstr;
> > response.setContentType("html/transfer");
> > out.clear();
> > tmpstr=download.getStrbuffer().toString();
> > out.println(tmpstr.trim());
> >%>
> >
> >
> >Anders B. Jensen
> >Consultant, Research & Development
> >LEC AS
> >
> >Remove the SPAMLESS to mail me.
>
-
Hi,
Is it possible to download excel file on the server on a JSP page. Kindly advice.
Thanks in advance.yes...
What is the scenario....
is it..
1. You have a XLS on server...alredy created..
2. Now you need a link on JSP page....that is linked to this EXS file...
3. User acess your web application and click on link....
4. A popup comes up....and user selects either to save or download the file....
Is this your scenario....
If not then specify steps you are looking for....and you face issue in which step....
Edited by: Saurabh Agarwal on Jul 6, 2011 12:21 PM -
Excel File downloaded from application server is also opening in notepad
Hi Friends,
While downlaoding an excel file from the application server,we are able to open in notepad also.But this does not conatin the excel properties and hence happening.File should only oopen with excel and no other file type
Can any open help on this
ld_file = '/usr/sap/trans/abap/HR_DATA.xls'.
OPEN DATASET ld_file FOR OUTPUT in text mode ENCODING DEFAULT .
IF sy-subrc = 0.
LOOP AT int_final.
CLEAR wa_string.
CONCATENATE int_final-employee_sno int_final-employee_code INTO wa_string SEPARATED BY con_tab.
CONCATENATE wa_string int_final-first_name INTO wa_string SEPARATED BY con_tab.
please help...
Edited by: Neliea on Oct 29, 2009 1:11 PMHi,
Please refer to these links.
[url]Re: Internal table to excel download?;url]
[url]Re: Transfer from Internal Table to EXCEL file...;url]
Regards,
Aditya -
Column is shifted to 1 position right ( Excel file downloaded from ALV )
After downloading the data into the excel file from ALV ... i checked the file & i came to know that all the columns are shifted to 1 position right. Can anyone help me? Is there any sap notes available for this problem
Hello
What is the result if you open the exported file via 'File => Open' in the excel program?
what is you current basis level?
Jude -
Regarding excel file download from webdynpro table element
Hi All,
I want steps to do excel download from webdynpro table element.
Thanks in advance.
Regards,
Muneesh Gitta.Hi Gitta,
There are 2 ways in doing it, one is using GUI DOWNLOAD FM or using class clwd_runtime_services.
DATA:
node_node_alv TYPE REF TO if_wd_context_node,
elem_node_alv TYPE REF TO if_wd_context_element,
stru_node_alv TYPE wd_this->element_node_alv,
itab_node_alv TYPE TABLE OF wd_this->element_node_alv..
navigate from <CONTEXT> to <NODE_ALV> via lead selection
@TODO handle not set lead selection
IF ( node_node_alv IS INITIAL ).
ENDIF.
get all declared attributes
node_node_alv->get_static_attributes_table(
IMPORTING
table = itab_node_alv ).
DATA:
node_file_download TYPE REF TO if_wd_context_node,
elem_file_download TYPE REF TO if_wd_context_element,
stru_file_download TYPE wd_this->element_file_download ,
item_fname LIKE stru_file_download-fname.
navigate from <CONTEXT> to <FILE_DOWNLOAD> via lead selection
node_file_download = wd_context->get_child_node( name = wd_this->wdctx_file_download ).
get element via lead selection
elem_file_download = node_file_download->get_element( ).
get single attribute
elem_file_download->get_attribute(
EXPORTING
name = `FNAME`
IMPORTING
value = item_fname ).
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = item_fname
FILETYPE = 'ASC'
TABLES
data_tab = itab_node_alv.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
OR
check this blog for
Re: Export to Excel Sheet functionality -
Hi,
I am facing the problem in opening the word and excel files received through email in my MS office professional 2013 paper licence, Microsoft Windows 8.1 enviornment. please help in this matter
regards
Rajeev Bhagwat
Administrative Officer-I
Purchase and Store Section
UGC-DAE Consortium for Scientific Research,
University Campus, Khandwa Road, Indore (M.P.), India.
Telefax-+917312361546I should further say the files I sent are .xlsx and .docx files. They look fine my end and I send such files all the time without problems.
However, I did try to cheat by going in via the Safari onto my 'live' online email account and the Safari automatically transfers them to winmail.dat files with the same result.
Ahh - have just been on using my PC this time and you are right, it seems that the service provider does the transfer and then when my outlook opens the file (on the PC), it must reconvert to .xlsx etc again.
Very strange.
Ergo, I guess the question should be how I open wimail.dat files ?? -
Questions regarding jsp file download from blob
Hi developers, i'm doing jsp file download from a blob column in DB2 using struts,
1) How do i design the jsp page such that the page will show perhaps a hyperlink for me to download the file?
2) What about struts-config.xml? Do i need to modify any mappings there?
It would be great if some kind developers were to provide some sample codes for me. Thanks alot. Your effort is kindly appreciated.http://kr.forums.oracle.com/forums/thread.jspa?threadID=1982213 - looks similar, you may need to change contentType as per use case
-
Excel 2013 doesn't display .xls file downloaded from Wells Fargo (Inconsistent)
I have two computers exhibiting the same problem but not every time.
Windows 7 Pro 64-bit
Office 2013 64-bit
Download an .xls file through Chrome or IE.
Download is fine
Attempt to click to open.
Excel Launches, appears in the taskbar, file never opens... Excel is unresponsive.
Right Click Task Bar icon, program will close. You can open other files just fine.
I noticed when you double click the file to open, two excel.exe processes open in Task Manager... not sure if that is normal. When you close excel, they both disappear.
Thoughts?Hi,
In regarding of the issue, please provide us more information to assist you better.
Did this issue only occur with the .xls files downloaded from Wells Fargo website? Have you tried from other website, such as OneDrive?
Have you tried to download some .xlsx files to test from Wells Fargo website?
Please do some tests to narrow down the issue.
1) Try to convert the .xls files to .xlsx files, if we can open the .xlsx correctly, this issue may be caused by the compatibility issue between Office 2013 and Office 97-2003 format. Thus, I recommend you convert the file to Excel 2013
format.
2) Open the Excel program first=>Click Open=>Navigate to the file=>Then open it. If it also can be opened correctly, this issue may be caused by the Dynamic Data Exchange. Please try to turn off the "Ignore other applications that use
Dynamic Data Exchange (DDE)“ setting.
Steps:
1.Click the File tab, and then click Options.
2.Click Advanced, scroll down to the General section, and then clear the Ignore other applications that use Dynamic Data Exchange (DDE) check box in the General area.
3.Click OK.
If you have any update, please feel free let me know.
Regards,
George Zhao
TechNet Community Support
It's recommended to download and install
Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
programs.
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact [email protected] -
I am unable to open attachments (Word Documents, Excel file, Adobe) from my Gmail with Firefox. My computer freezes when I try to open the (email attachment) file. Task Manager says "not responding".
You can respond to [email protected]You may first want to look into Safari's "Installed Plugins" section within the browser. This is (usually) found under the Safari Help header in the top of a browser. I say usually, because I don't use Safari often and mine is an older version. They handle applications and plugins like most others, to a point.
I see in Safari Installed Plugins that mine would use
application/pdf
Acrobat Portable Document Format
Acrobat Reader & reader plugin v9.5.5 for web browsers
(in Safari 5.x, where I looked into this)
While I use FireFox, SeaMonkey (Mozilla) and others, where I can choose in preferences the helper applications to open from the browser, Safari has different methods; so if you can change this in the preferences or settings of Safari in a later version I am not certain.
You could see what the defaults are by using Safari help menu to open the Installed plugins, and maybe find out what happend to Adobe reader plugin. Could be it was 'sandboxed' in a later OS X and needs to be installed differently to be accepted as safe.
It is easier to set how a file type is handled once it is inside the computer and not held in the browser; by file type in general or specific to each single document. I do both, and seldom let an a browser do these things due to security considerations. I download and open them, only then if I feel they are safe.
Sorry to not have a specific answer for that anomaly.
Good luck & happy computing! -
Make files downloadable from outside tomcat(web) context
Hi there,
I made an application on whicht people can upload word/pdf files.
I put them in a dir called /opt/customer/2342/ , where 2342 is the customer id.
The files are stored there, because I don't want people to be able to just download the files by using http://www.blahblah.com/customer/2342
Now I want to create a servlet or jsp file that is able to make the files downloadable for specific users.
Of course I can find the files using java.util.File. But I don't have a clue how to make them downloadable from this path. Should it be something with a FileStream... ?? And adding the mime-type?
Can anybody give me some hints on making files downloadable from a specific dir?
Thanks in advance.
Jeroen van Hertumhere is a servlet that is used to load files that are stored on the file system. The user submits the file path releative to a know file path.
package common.servlet;
import java.io.*;
import java.net.*;
import javax.naming.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.log4j.Logger;
public class FileResourceServlet extends HttpServlet
// -------- Static fields ----------------------------------------------
// Logger
private static Logger logger = Logger.getLogger(FileResourceServlet.class.getName());
* Root context for all JNDI lookups
private static final String ROOT_CONTEXT = "java:comp/env";
* JNDI lookup name of the binary path value
private static final String BINARY_PATH_KEY = "binaryPath";
* Default in case looking it up from the environment fails
private static final String DEFAULT_FILE_RESOURCE_PATH = "/home/cp/bin";
// -------- Fields -----------------------------------------------------
private String fileResourcePath = null;
// -------- Methods ----------------------------------------------------
* Initializes the servlet.
public void init(ServletConfig config) throws ServletException
super.init(config);
try
//Get Norm's info
Context initCtx = new InitialContext();
Context envCtx = (Context)initCtx.lookup(ROOT_CONTEXT);
fileResourcePath = (String)envCtx.lookup(BINARY_PATH_KEY);
catch( Exception e )
logger.error("Error looking up file resource path, going with " +
"default value - " + DEFAULT_FILE_RESOURCE_PATH, e);
this.fileResourcePath = DEFAULT_FILE_RESOURCE_PATH;
logger.debug("File Resource Path:" + fileResourcePath );
* Destroys the servlet.
public void destroy()
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
protected void processRequest(HttpServletRequest request,
HttpServletResponse resp)
throws ServletException, IOException
ServletContext sc = getServletContext();
String pathInfo = request.getPathInfo();
logger.debug("Path Info: " + pathInfo);
if (pathInfo!=null && !pathInfo.startsWith("/")) pathInfo = "/" + pathInfo;
String filename = fileResourcePath + pathInfo;
logger.debug("Binary Filename:" + filename );
// Get the MIME type of the image
String mimeType = sc.getMimeType(filename);
if (mimeType == null)
//sc.log("Could not get MIME type of " + filename);
logger.warn("Could not get MIME type of " + filename);
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
// Set content type
resp.setContentType(mimeType);
// Set content size
File file = new File(filename);
resp.setContentLength((int)file.length());
// Open the file and output streams
FileInputStream in = new FileInputStream(file);
OutputStream out = resp.getOutputStream();
// Copy the contents of the file to the output stream
byte[] buf = new byte[2048];
int count = 0;
while ((count = in.read(buf)) >= 0)
out.write(buf, 0, count);
in.close();
out.close();
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
processRequest(request, response);
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
processRequest(request, response);
* Returns a short description of the servlet.
public String getServletInfo()
return "Short description";
} -
Just bought a new Imac OX 10.9. Installed contents from previous Time Machine. All looks good. But, now, when I try to open any file downloaded from interent (like the Amazon mp3 downloader, for example or a plugin update) I get this message:
"XXX can’t be opened because it was not downloaded from the Mac App Store" . Help! ThanksGot it solved! System preferences, security & privacy icon, general: allow apps downloaded from Mac Store and Identified developers! Phew!
-
Files recently downloaded from Canon Legeria FS306 to iMovie '11 do not play the audio. I can still hear audio on the camera or by downloading the same files to a PC. Can also hear audio on earlier files downloaded from the same camera to iMovie '11. How do I avoid this problemand recover lthe ost audio?
The first thing to try is to run Software Update (the Update tab in the Mac App Store.). This was an issue a couple of releases ago, and an update seemed to fix it.
If you are already at the most recent version of iMovie, then I don't know how to solve you issue. Maybe someone else will have some ideas. -
APEX 4.0: error while opening a XLS file downloaded from interactive report
Hi,
I'm getting below error while opening a XLS file downloaded from an interactive report (APEX 4.0).
"The file you trying to open, 'customer_2.xls', is in a different format than specified by the file extension.
Verify that the is not corrupted and is from a trusted source before opening file. Do you want to open file."
Yes No Help
May be this one Apex 4.0 issue.
please help me.
Thanks
MukeshHi,
is the next part of the code correct.
What i mean is packing of the attachment, finding out the size of pdf file and doc type as PDF.
You can also try below link..
Link: [http://wiki.sdn.sap.com/wiki/display/Snippets/SENDALVGRIDASPDFATTACHMENTTOSAPINBOXUSINGCLASSES]
Hope this helps.
Regards,
-Sandeep -
Hi All,
I have written a code that downloads a file from server using the following link given by Frank,
File download from server
I am able to get a open/save/cancel dialog with help of this. But issue is that applications of kind .doc/.xls/.ppt gets opened (If user clicks open) right in the internet explorer window instead of getting opened in a new office application....
However .pdf runs fine.
Can any thing be done for this???
Any help....
Regards,
AmittHi,
what do you have for the content disposition header?
Try this:
response.setHeader("Cache-Control", "max-age=0");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fname + "\"");
response.setContentType("application/x-download");Brenden
Maybe you are looking for
-
Adding Controls dynamically in the Infopath/Web form with dynamic controls
Hello, The client requirement is to create SharePoint solution for the below image. A web form/Info-path form will be created where user can enter the details and data will be submitted. I am looking for a solution to implement the requirements in Sh
-
Calendar Error - "You response to the invitation cannot be sent."
I'm not sure why, but for some reason when I replied on my iPone to a single instance of a recurring meeting request (change in the "location"), I started getting this error message when I had either mail or calendar open. I currently have my compan
-
If I want to collect my email and calander by Acti...
If I want to collect my email and calander by Activesync over gprs which Nokia phone do I get? I have to connect to our in house Exchange sever. I can do this on the rubbish SPV phone that they gave me but I mant to use a Nokia. I alreasy have two Se
-
Adobe Premiere Elements 11 Editor and OS Mavericks
I installed OS Mavericks for Mac and my Adobe Premiere Elements 11 Editor doesn't work more. What must I do?
-
Is there a way to get my photo back after my phone was stolen and I backed up on iCloud?
Hi was wondering if there was a way to get my photos off my stolen phone as I backed up to iCloud?