Excel file download in jsp

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

Similar Messages

  • 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...

  • Opening Excel  files from a JSP page

    Hi,
    I am not able to open up an Excel file through JSP.
    I am using following code snippet in JSP page
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition","inline; filename=Test.xls");Do i need to do additional settings for rendering Excel from a JSP
    Thanks in advance !!!

    Hi,
    In my application , we have Excel files on the server i.e we are not creating excel sheets.
    I just want to display these static excel files through a jsp.
    I am able to display the excel files by reading them into ByteArrayOutputStream
    <%
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition","attachment; filename=B.xls");
    ServletOutputStream so = response.getOutputStream();
    String filename = "D:\\Test.xls";
    String mimetype = "application/vnd.ms-excel";
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    InputStream in = new BufferedInputStream(new FileInputStream(filename));
    byte bytebuff[] = new byte[500];
    for(int lengthread = 0; (lengthread = in.read(bytebuff)) != -1;){
    output.write(bytebuff, 0, lengthread);
    byte data[] = output.toByteArray();
    response.setContentType(mimetype);
    so.write(data);
    in.close();
    so.close();
    %>But my question is that , do i really need to do all this for rendering excel through a jsp.
    Can't i do it by just setting the content type ?
    Thanks

  • Problem making an Excel file from a jsp

    Hi.
    I'm developing a web application that uses Excel for printing the reports. So far everything has worked fine, at least for the created Excel files that do not have any images on them. Now I need to create an excel file with an image as the header. I tried adding the necessary code to include the image, but when I open it, the image is not displayed (like when you open an HTML page that could load a certain image). I tried using different ways to set the src to see if maybe the path was the problem, but everytime I got the same result...
    How can I do this? How can I include the image and actually display it when the user opens the file in Excel?
    Thanks in advance
    CyberSpider

    I had a similar porblem....
    I got some help from...http://www.javaworld.com/javaworld/jw-10-2006/jw-1019-xmlexcel.html?page=1...
    This is my code in servlet...
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet spreadSheet = wb.createSheet("Users");
    spreadSheet.setColumnWidth((short) 0, (short) (256 * 25));
    spreadSheet.setColumnWidth((short) 1, (short) (256 * 25));
    // Creating Rows
    HSSFRow row = spreadSheet.createRow(0);
    HSSFCell cell = row.createCell((short) 1);
    cell.setCellValue("Year 2005");
    cell = row.createCell((short) 2);
    cell.setCellValue("Year 2004");
    HSSFRow row1 = spreadSheet.createRow(1);
    HSSFCellStyle cellStyle = wb.createCellStyle();
    cellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
    cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
    cellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
    cellStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
    cell = row1.createCell((short) 0);
    cell.setCellValue("Revenue ($)");
    cell = row1.createCell((short) 1);
    cell.setCellValue("25656");
    cell = row1.createCell((short) 2);
    cell.setCellValue("15457");
    FileOutputStream output = new FileOutputStream(new File("/tmp/Users.xls"));
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment;filename=Users.xls");
    ServletOutputStream out = response.getOutputStream();
    wb.write(output);
    output.flush();
    output.close();
    forward = null;
    In firefox i get the download dialog box but not able to open in from there,i need to save it and then open. In IE i dont get the dialog box instead the excell open inside the browser......Please help me to open a excel sheet onclick on a link "Export to excel" in jsp......
    Thanks in advance...

  • Excel file download issue

    Hi Experts,
    I am downloading an excel file which is stored at the MII server using JSP file. I am using the below code for the same. I am able to download the excel file successfully but when I open the same I get some junk value as content. I mean to say the content is not at readable format. I have tested the java code using standalone program where it worked successfully.
    I  tested this JSP at MII 12.2 and MII 14.0 and both provided same result. I have attached the screenshot of excel how it looks after opening
    I want to know is this a problem with Netweaver web server?. I mean the way it runs JSP. Unfortunately I could not test this on another web server
    Any help on this is very much appreciated.
    <%
      String filePath = "C:\\myfile.xls";
      try
      FileInputStream in = new FileInputStream(filePath);
      response.setContentType("application/vnd.ms-excel");
      response.addHeader("content-disposition","attachment; filename=" + filePath);
      int octet;
      while((octet = in.read()) != -1)
      out.write(octet);
      in.close();
      out.close();
      catch(Exception e)
      out.println("Exception occured:"+e);
    %>
    Thanks
    Shaji

    Hi Christian,
    Thanks for your response.
    I tried that as well but same result. I get a alert message as below while opening the file.
    "Excel cannot open the file Demo.xls because the file format or file extension is not valid. Verify that file has not been corrupted and that the file extension matches the format of the file"
    I am trying to run the same file on another web server such as tomcat and see if the issue persist.
    Thanks
    Shaji

  • Excel file processing in jsp

    Hello friends
    I want to read Excel files jsp(or java).I used sql driver,but it does'nt reads the file properly.I want to read file in jsp.I went thr many sites and found many ways like apache poi,JExcel api etc
    I found JExcel api is not free.I am getting errors with poi.I found no proper documentation on it.On apache site there are many versions to download poi packages.I confused about which to download.
    If any one has used poi successfully,please let me know

    related to POI
    **POI**
    Site
    http://poi.apache.org/Api
    http://poi.apache.org/apidocs/index.htmlExamples
    http://www.google.co.in/search?hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&hs=7WV&q=POI+examples&btnG=Search&meta=

  • Garbage characters in excel file opened by jsp

              I am storing an excel file as blob in database. While retrieving
              from database when I open in the jsp page , it shows a lot of garbage characters
              and all formatting is lost. I am using content type "application/vnd.ms-excel".
              I am also setting correct mime type in web.xml as application/excel. It is weblogic
              6.1 sp2 with oracle 8.1.6. the pdf and word docs are working well. Please help
              soon.
              Thanks
              

    Download the Open G Toolkit from www.openg.org. There is a VI called Quit Application.vi that works great. I have used it with the very stupid Brooks 0154 SmartDDE Controller program to reset the application.
    Be sure to save the document and close the DDE communication first.
    Michael
    www.abcdefirm.com
    Michael Munroe, ABCDEF
    Certified LabVIEW Developer, MCP
    Find and fix bad VI Properties with Property Inspector

  • Open an excel file in a jsp

    using apache poi excel, i created a workbook and add that into the season and opened in new jsp by servletoutputstream(these are happening at onclick).
    first time it's working fine,
    if i try do it again without closing this jsp, I am getting the same results in the previous jsp.But this works fine if i close the the jsp and do that.
    regards
    Senthil Arjunan

    duffymo wrote:
    SoulTech2012 wrote:
    duffymo wrote:
    That's fine, but you can serve up an Excel file (for download) with a couple lines of code. That doesn't require Spring. Too often I see these noobs working on a web project and throwing half a dozen frameworks at it because people told them to or recommended them. Noobs don't often know better and I have no doubt that some of them would attempt to use Spring just to get an Excel file to download if they were told to. But then again, that's their problem I guess.You win. What did I win?The debate, of course.
    Do you realize how often this question is asked and how many times the code has been posted?! No, which is why I asked. Please post them just one more time.Nobody likes a smart@ss. I seriously doubt, as much time as you spend here, that you truly believe that. Yes, I'm calling you a liar.
    >
    Besides, I have no interest in helping to set a precident that there's no need to do any research when you can simply ask for a handout here. Posting the code, or not, is still a better response than recommending Spring.Fine. Post the code.
    %knock yourself out!
    in 60 seconds I found a half dozen posts of the same exact code
    http://search.sun.com/search/onesearch/index.jsp?qt=download+excel+file&rfsubcat=&col=developer-forums&cs=false&rt=true&reslang=en

  • 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.
              >
              

  • Regarding ALV output  to Excel file download

    Hi all,
    i had a requirement when downloading the ALV output to the Excel file it should ask for the password.if the user enters the password then this pass word shuld be assigned to the  Excel file that was downloaded.
    Can i know how this can be implemented

    Hi,
    Using EXCEL_OLE_STANDARD_DAT you can specify the PASSWORD & PASSWORD OPTION.
    Regards,
    Sharat

  • Problem In Excel File download

    Hi
    I have created an excel file fro table using HSSF api.When i click on the link download excel,it opens properly but an empty new window also opens along with it..i do not want that to happen
    any Suggestions??

    Hi,
    I also tried for it but couldnt get any solution.I think it is the default behaviour.
    Regards,
    Sudhir

  • Excel File Download and Drop downs at Column Level

    Hi All,
    I am able to download the excel file, but I want to include dropdowns for each column. So that using those values user can add new records using the drop down list values.
    I am thinking it is not possible. Can some one validate me..?
    I have another approach.
    I will download masterdata and the Filedata to the excel and later i will create the relation to show the listbox. But i am not able to download(add the tab) to the existing Excel file. In short is it possible download the multiple files into a single excel file, with different tabs.
    Thanks and Regards
    Vijay

    Hello,
    As you wanted to include dropdowns for each column, it is possible in two ways.
    Way1: Statically
    Create a View element with type Dropdown by key as one of the table column -->bind the property 'Selected Key' to the required attribute(Since attribute type will be specified to be the data element and within domain can have Fixed values --> The table column would be automatically displayed with dropdown entries.
    Way2: Dynamically
    In the WDDOINIT method of that view where you have dropdownkey element has located -->Write the following code
    DATA:    lo_node_info             TYPE REF TO    if_wd_context_node_info.
      lo_node_info->set_attribute_value_set(
        EXPORTING name      = 'Attribute_Name'
                  value_set = lt_value_set ).
    lt_value_set shall be populated with the data that you wanted to display in the dropdown.
    Thanks,
    Bharath.K

  • 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 PM

    Hi,
    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

  • PDF files download as JSP

    I just upgraded to Leopard 10.5.6 this weekend from Tiger 10.4.11 then upgraded to 10.5.8. All went well except for a small glitch in Mail which I got fixed with the help of this forum. My newest problem is this morning I went online to my bank to download our monthly statement which always is in PDF format. The file downloaded fine, except the file title says it's a PDF, but the extension is .jsp. I contacted the bank and they have changed nothing so I am wondering is there a setting I need to change somewhere that would affect the download? At present I haven't found an application that will open .jsp files, but first I want to get them back to PDF format. Any suggestions will be appreciated.

    Title Man wrote:
    I just upgraded to Leopard 10.5.6 this weekend from Tiger 10.4.11 then upgraded to 10.5.8. All went well except for a small glitch in Mail which I got fixed with the help of this forum. My newest problem is this morning I went online to my bank to download our monthly statement which always is in PDF format. The file downloaded fine, except the file title says it's a PDF, but the extension is .jsp. I contacted the bank and they have changed nothing so I am wondering is there a setting I need to change somewhere that would affect the download? At present I haven't found an application that will open .jsp files, but first I want to get them back to PDF format.
    Have you tried renaming the file so that its extension is ".pdf"? I believe I regularly download PDF files that have "jsp" in the file name, but renaming them corrects the problem.

  • Help Regarding excel file download

    Hi,
    I have developed a object with alv list display aand in the selection screen maintained a checkbox for EXPORT TO EXCEL..
    and for each and every field in the field catlog  wriiten the code like
    IF P_EX = 'X'.
          LS_FIELDCAT-ROW_POS    = '1'.
          LS_FIELDCAT-COL_POS  = 1.
    But this output is not flowing into excel file when executing...can anyone help me how to download the output data into excel file when we execute.because this report runs in the background and after execution data should be flown into excel file.
    Regards,
    Venkat.

    Hi Venkat,
    use this Function module to download the file
    CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          FILENAME                        = 'C:\Documents and Settings\sap\Desktop\Hierarchy.xls'
       WRITE_FIELD_SEPARATOR           = '#'
        TABLES
          DATA_TAB                        = gt_target.
    Here gt_target is the internal table which holds the data.
    Hope this solves your purpose...
    Regards
    Sajid

Maybe you are looking for

  • Disabling the creation of sample application for new workspace

    Hi, Just wondering if it's possible to disable the sample the application that is created when ever you create a new workspace? Also so that it doesn't create the 'demo' tables and associated sequences. Pretty sure we have this configured at work, bu

  • Free Goods Condition Records Extraction.

    Hi All, Is there any standard Report or a Table from which extraction of Free-Goods condition records can be done based on Sales org and Customer. Thanks.

  • How to send a mail to Cell phone number

    Hi,   Here we are running several jobs a day and we would like to send a mail or information to cell phone number or pager when the job is failed. Is any body have any idea how do we send a mail to Cell number or Pager. If any body knows please advic

  • Multiple UPDATE statement in a message

    Hi Experts, Here is a scenario where we need to send multiple UPDATE statements in single message the structure is as below. <Table_name> 0..unbounded occurrence            <action> UPDATE            <access>                    <non key fields>      

  • Following the Hello World Tutorial for Microsoft Windows - PROBLEM

    Okay, I have my Command Prompt up and I was on the C Drive, I put in javaAnd a bunch of text came up, then I wanted to change HelloWorldApp.java to a .class file so I typed in javac HelloWorldApp.javaAnd an error popped up: 'javac' is not recognized