Problem when opening excel sheet in jsp

Hi friends
When i try to open excel sheet from my program I am getting two problems
1. first row of excel sheet is empty
2. while opening I am getting error message of "the file is not in a recognizable format"
Please help me..It is an urgent work
my code
<%@page language="java" import="java.io.*,java.text.*,java.sql.*,java.util.*"%>
<%
Class.forName("org.gjt.mm.mysql.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://256.136.119.86/mydb","zzz","zzz");
Statement st = conn.createStatement();
StringBuffer sb = new StringBuffer();
sb.append("SAP#" + "\t");
sb.append("x-plant status" + "\t");
sb.append("Total Amount" +"\t");
sb.append(">90 days" + "\t");
sb.append("\n");
try
String query="select * from temp_Xplant";
ResultSet rs = st.executeQuery(query);
while(rs.next()){
sb.append(rs.getString("sapNo") + "\t");
sb.append(rs.getString("status")+ "\t");
sb.append(rs.getString("amt") + "\t");
sb.append(rs.getString("days") + "\t");
sb.append("\n");
conn.close();
st.close();
catch (Exception e)
out.println("error");
conn.close();
st.close();
response.setContentType("application/vnd.ms-excel");
// response.setHeader("Content-Disposition", "attachment; filename=\"test.xls\"");
String testt = "tests.xls";
response.setHeader("Content-Disposition", "attachment; filename="+testt);
out.println(sb.toString());
out.close();
%>
thanks in advance

The problem here is, you have setted the content type as excel sheet and you are writing some String content into the output stream. when excel tries to read the String content it will surely throw some error. Lot of excel APIs are available in the market to generate excel sheets.
you can find one in the below URL.
http://www.teamdev.com/downloads/jexcel/docs/JExcel-PGuide.html

Similar Messages

  • How to open Excel Sheet using JSP?

    Hi Dear,
    I want to open Excel Sheet in client browser, How to do this using JSP?
    If it is possible to open, client can make the changes in the sheet if he saves those changes, those changes must reflect on server.
    So pl. tell me how to do this?
    Thanks

    The following code gets data from an ODBC link to an Excel spreadsheet and displays it as a HTML table. You can modify the table to include <input> fields to update the spreadsheet when the form is submitted.
    I hope that this helps. -Don
    <%
    /* Establish connection to excel database(spreadsheet)
    ODBC DSN="xltest" */
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    java.sql.Connection con= java.sql.DriverManager.getConnection("jdbc:odbc:xltest");
    java.sql.Statement st = con.createStatement();
    java.sql.ResultSet rs = st.executeQuery("SELECT * from [Sheet1$]");
    java.sql.ResultSetMetaData rsmd = rs.getMetaData();
    %>
    <html>
         <head><title>Excel Database connection test</title></head>
         <body><table border=1 cellspacing=0><tr>
    <% // Print Column headings (first row of spreadsheet)
    for (int i = 1; i <= rsmd.getColumnCount(); i ++){
              %><td id='td1'><%=rsmd.getColumnName(i)%></td><%
    }//End for
    %></tr><%
    while(rs.next()) { // Print row data
    %><tr><%
         for (int i = 1; i <= rsmd.getColumnCount(); i ++) {
                   %><td id='td2'> <%=rs.getString(i)%></td><%;}// End for
    }//End while
    st.close();
    con.close();
    %>
    </tr></table></body></html>

  • Installing Control Panel 2/3 causes problems in opening Excel sheets

    After installing the control panel 3.0, I can't open Excel sheets properly anymore. A message says that the Excel sheet contains corrupted data and Excel can try to restore them. After confirming this, the excel sheet shows opened but all formating is gone.
    I had this issue yet with Control Panel 2.0. After some research on the web I found out that the problem is caused by the CP for Windows. I then switched back to CP V 1.1.4 and the excel sheets opened properly again.
    Thanks for any advise. I'm using Windows 7 and Excel/Outlook 2007.

    You are downloading software illegally. ShapeShifter is shareware so unless you indicate that you paid for it I don't feel it is appropriate to post your issue in this forum setting.

  • Warning from Excel when opening Excel document in JSP

    Hi,
    I populate a HSSFWorkbook with data retrieved from a database using user input. I then want to open the excel file up so the user can see it.
    This works fine, but prior to the file opening I get a warning message from Excel saying that the file is of another format etc etc do you still want to open. It actually takes the name of the JSP page as the name of the file I want to open. The file opens if I ignore the warning.
    I do the following when opening the file:
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
    ServletOutputStream out = null;
    try {
    // Initiate servlet response
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-disposition", "inline;filename=\"" + excelSheet.getFile().getName() + "\""); //ExcelSheet getFile() returns java.io.File
    out = response.getOutputStream();
    excelSheet.getWb().write(out); //get HSSFWorkbook
    // Finalize task.
    out.flush();
    } finally {
    // Gently close stream.
    close(out);
    Any tips?

    This would occur only in a certain widely used webbrowser developed by a team in Redmond. It completely ignores the filename part of the content disposition header, takes the part after the last slash of the URL as the actual file name, examines its extension against the platform specific list of file associations and in case of an unknown filetype it reads the content type header and gives a warning before when the content type is different.
    To solve this problem, you need to append the filename as part of the URL. You can get some ideas out of this: [http://balusc.blogspot.com/2007/07/fileservlet.html].
    Its market coverage if fortunately shrinking, but until then we, developers, have to live with that product. It works perfectly in all other webbrowsers.

  • Firefox hangs when opening excel sheet in microsoft sharepoint

    When opening a excel sheet in Microsoft sharepoint Firefox hangs / freezes. (not responding)
    Only solution is to select end task in task manager.
    This is with version 3.6.8 ( there is no problem with 3.6.4)
    == URL of affected sites ==
    http://

    The problem here is, you have setted the content type as excel sheet and you are writing some String content into the output stream. when excel tries to read the String content it will surely throw some error. Lot of excel APIs are available in the market to generate excel sheets.
    you can find one in the below URL.
    http://www.teamdev.com/downloads/jexcel/docs/JExcel-PGuide.html

  • Problem when printing Excel sheets when downloaded from Portal

    Hey,
    I am using the desformat=spreadsheet option to generate Excel files for my reports downloaded from Portal and this works fine. The trouble is that when users go to print the downloaded Excel reports it seems that the scale of the report changes and everything is made smaller to try and fit on the one page. The font size decreases, and the scale of the report decreases to the point where the report is nearly unreadable when printed. But when just viewing the reports in Excel everything looks fine.
    Any suggestions on why this is happening and how it can be fixed?
    Thanks

    Hello hermannedem,
    If you cannot see any content on pages you printed or in print preview, the cause might be margins which are set too high.
    #In order to check the margins, we need to go to ''File'' > ''Page Setup''.
    #Once this is done, switch to the ''Margins & Header/Footer'' tab.
    #Check what's set there under ''Margins''.
    The following are the default values for ''Margins'':
    '''Right''': 12.7
    '''Top''': 12.7
    '''Left''': 12.7
    '''Bottom''': 12.7
    Check these values accordingly and change them if necessary.
    Please let us know, if this resolves the issue.
    Thanks!

  • EXCEPTION RAISED WHILE OPENING EXCEL SHEET FROM E-BUSINESS SUITE FORM

    Hi,
    I got error message ORA-10656I when was trying to open excel sheet which is in my local drive from e-business suite form. the following is the code where it is raising error.
    Appid := dde.app_begin('C:\Program Files\Microsoft Office\Office12\EXCEL.EXE '||'D:\emp.xls' ,dde.app_mode_normal);
    Oracle EBS version : 11.5.10.2cu
    Server : HP
    OS : HP Unix 11.11
    Could anyone help me out
    Thanks

    Two different forum users, exactly the same question? Hardly possible. So I guess this is just a double post.

  • Opening Excel sheet from server

    Hi I have one requirement to open Excel Sheet.
    The Excel sheet is residing in a directory parallel to WEB-INF. I am using Jboss server in Linux. in UI whenever I click on link I have to open Excel sheet from the server. Before opening Excel sheet I have to fill with some data. i am using JSP/Servlets .
    Can any one help me on this?
    Guru

    this piece of code is just open a xsl file with writing some data on the file
    it may be helpful for u .i am giving only logic.
    import java.util.*;
    import java.io.* ;
    import java.text.* ;
    public class a{
         // Main method
         public static void main (String args[])
              // Stream to write file
              //File file;
              FileWriter fout;
              String TimeStamp;
              try
              // Open an output stream
              Calendar currentdate= Calendar.getInstance();
                   int currmonth=currentdate.get(Calendar.MONTH)+1;
                   String strMonth="";
                   if(currmonth<10)
                        strMonth="0"+currmonth;
                   String wbname="Equifax"+strMonth+currentdate.get(Calendar.YEAR)+".xls";
                   System.out.println(wbname);
              BufferedWriter outfile = new BufferedWriter(new FileWriter(wbname));
                   //file=new File(filename);
                   fout = new FileWriter (wbname);
              // Print a line of text
              TimeStamp = new java.util.Date().toString();
              //String filename1=file.getName();
              outfile.write(" Apply ");
              // Close our output stream
              outfile.close();          
              // Catches any error conditions
              catch (IOException e)
                   System.err.println ("Unable to write to file");
                   System.exit(-1);
    }

  • Problem in opening spread sheet from iview

    Hi Experts,
    I have a ecc report integrated as an iview in enterprise portal. I am trying to preview the iview and
    run the report. Iu2019m successfully executing the report, but while saving the report as a spread sheet (exce file to local drive)though 'menu' item the following problems occurred:
    1) Excel sheet is not opening on clicking on the 'generate' tab on the report
    2) File is created but not found in local drive.
    3) We are seeing this " "The application's digital signature has an error,Do you want to run the application".After then it showing a pop up box (small applet window) unable to execute the program."?
    Pls help me in this regards as it is urgently required for me
    Thanks,
    Jyoti

    hi
    You have problems with conversion OTF to PDF.
    u can use this FM  SX_OBJECT_CONVERT_OTF_PDF  for do it.
    part of code:
    data:       i_objbin like solisti1 occurs 0 with header line,
          i_otf type solisti1 occurs 0 with header line.
        call function 'SX_OBJECT_CONVERT_OTF_PDF'
          exporting
            format_src            = 'OTF'
            format_dst            = 'PDF'
            devtype               = 'PRINTER'
      FUNCPARA              =
            len_in                = '1234'
    IMPORTING
      LEN_OUT               =
          tables
            content_in            = i_otf ""your table OTF Format
            content_out           = i_objbin
            exceptions
           err_conv_failed       = 1
           others                = 2
    Look this Forums :  problem opening pdf file
    Regards
    Gregory

  • How to solve the problem when opening program illustrator cs6 ERROR: 16 It is WINDOWS 8.1 / 64 BIT help please

    how to solve the problem when opening program illustrator cs6
    ERROR: 16
    It is WINDOWS 8.1 / 64 BIT
    help please

    Thanks, Jeff! The file Adobe Setup Error.log contains the following information:
    02/14/14 07:20:26:474 | [INFO] |  | OOBE | DE |  |  |  | 8860 | DEVersion: 5.0.0.0
    02/14/14 07:20:26:475 | [INFO] |  | OOBE | DE |  |  |  | 8860 | Loading library from C:\Program Files (x86)\Common Files\Adobe\OOBE\PDApp\DECore\DE5\Setup.dll
    [    8860] Fri Feb 14 07:20:26 2014  INFO
    ::START TIMER:: [Total Timer]
    CHECK: Single instance running
    CHECK : Credentials
    Load Deployment File
    CHECK : Another Native OS installer already running
    Create Required Folders
    Assuming uninstall mode
    Lookup for master payload
    [    8860] Fri Feb 14 07:20:26 2014 ERROR
    DW040: The product "{893B3B44-0A1E-404B-8FE8-0A74509102A9}" is not installed. Cannot proceed with the uninstall
    [    8860] Fri Feb 14 07:20:26 2014  INFO
    :: END TIMER :: [Total Timer] took 6.90443 milliseconds (0.00690443 seconds) DTR = 579.338 KBPS (0.56576 MBPS)
    -------------------------------------- Summary --------------------------------------
    - 0 fatal error(s), 1 error(s), 0 warning(s)
    ERROR: DW040: The product "{893B3B44-0A1E-404B-8FE8-0A74509102A9}" is not installed. Cannot proceed with the uninstall
    Please search the above error/warning string(s) to find when the error occurred.
    These errors resulted in installer Exit Code mentioned below.
    Exit Code: 33 - The product is not installed, cannot uninstall.
    Please see specific errors and warnings for troubleshooting. For example, ERROR: DW040 ...

  • Strange problem when opening word doc situated in WLS virtual dir

    Hi all,
    we have a strange problem when opening word doc
    situated in C:\Oracle\Middleware\as_1\forms\webutil
    we put some word docs there and tried to open from forms using for example web.show_document('http://wp0606:9001/forms/webutil/mug00103.doc', '_blank');
    no problem using FF, however in IE8 the word doc is shown in its binary format, this also happens when we try to open the doc in IE8
    however when we google and search for instance for a test.doc and then click on this url a file save dialog is shown
    that's why we believe that this might be due to a configuration issue of WLS
    any help would be greatly appreciated
    Kr
    Martin

    I think you have 2 ways to go here. Figure out what html is from wherever weblogic gets it, meaning you have to delve into the docs, snoop
    around in directories and find what it must be sending (This is going to be unavoidable if you are going to change what weblogic is doing.
    Sooner or later you have to try to figure out where it gets this stuff from)
    or
    you can experimentally snoop on your url with a tool like wget or curl. These are fundamental web tools.
    The latter is always a useful thing to be able to do. (you need to formulate a query to get the content-type).
    Whoever managed to get weblogic to serve any files in the first place probably can figure this out.

  • Problem when opening "Mail"

    Dear members of the Apple Community,
    After transferring my files and my profile on my new Macbook pro, I keep encountering a problem when opening "Mail". Each time I try, the app asks me to choose a mail account to add, but I already added the ones I normally use. I can either create/add this new account or click the "cancel" button. I cannot use the program (the main functions are not available). But if I try to add a new account, Mail does not upload the new messages for my existing accounts and if I click "cancel", the application simply close itself. What could I do?
    Thanks a lot to your help.

    It might be worth running Disk Utilities and then Repair Disk Permissions to see if that resolves the problem.
    Chris

  • I have a problem when opening a profile on Facebook. when I open the main page and facebook all ok but when I try to open your Firefox profile my block! what the problem ????? before me it was happening but now when I installed Firefox 4

    I have a problem when opening a profile on Facebook. when I open the main page and facebook all ok but when I try to open your Firefox profile my block! what the problem ????? before me it was happening but now when I installed Firefox 4

    WiFi signals get stronger the closer the machine is to the router and the less interference/blocking of the signal like via walls with metal in them or of thick concrete.
    Since the signal emanates outwards in a sphere, your supposed to place the wireless router in a central location in the building so it covers all areas.
    The power of the router also has a affect, if your router is old or something not that powerful like a Airport Express, it doesn't have the ability to filter out other signals or enough punch to get through walls etc. or cover a large area as effectively.
    If you buy/have a powerful router of newer make and have issues where there is metal in the walls or thick concrete, then you can buy something like OpenMesh and by using Ethernet cables from the back of the router, extend the WiFi signal into other rooms and areas past the blockage.
    https://www.open-mesh.com/

  • I have a problem when opening author book samples in iPad they dont open at the first page,

    i have a problem when opening author book samples in iPad they dont open at the first page, they open further in, can you explain what i need to do to correct this , Ron Ritter

    Book? I thought you said sample?
    Not sure how that is possible, sorry.
    How many users out of the total downloaded are having this issue?

  • Problem in opening excel file in different window

    hi
    i want to open excel file in different window it open in same window properly on the bases of condition but when i try to open in different with window.open( )
    it give error that file has already used or path not exist OR requisted site either unavailable
    how can i rectified

    Hi.
    I am too facing the same problem. I am using Jakarta Poi to display my resultset in an excel sheet directly(and not into a jsp)
    The browser opens a window showing Open Save Cancel. If i click and save the excel sheet and then open, it opens. But clicking on Open directly doesnt open the excel sheet. Rather it gives the same error
    The file name or path name does not exist.
    The file you are trying to open is being used by another progrtam . close the document in other program and try again
    The name of the work book your tring to save is the same as name of another document that is readonly .try saving workbook with different name
    Can somebody please help me fix this problem, since its an urgent requirement. Mail me at [email protected]
    Thanks
    Hitesh

Maybe you are looking for

  • How to download a text file using jsp i

    I want to provide download facility in jsp page. if i have exe download is working . If I have a text / html file it is just displaying I want to make it download How to do it? regards subrahmanayma

  • Dual-monitor setup + screen rotation

    Hello, I want to use my desktop computer with a dual-monitor setup. I have connected both monitors successfully, but problems arise after this point. The first problem is that they both just display the same screen and that xrandr only detects one sc

  • Connect two monitors to macbook air NEW model

    Hi Apple experts I know that this is not the first time people asking this question, but as I can see it is 1,5 year ago last time people asked. I have the new 1,6 ghz Macbook Air and I want to connect two external screens which both only have VGA an

  • Floating Point Type

    i have a input value say 213. i have to match it with a field in table AUSP-ATFLV( type F size 16 decimals 16) the data in the field is of format  2.1300000000000000E+02 how can i match the value 213 with this value.

  • Podcast names

    hey guys, basically my question is, how do I change the name of my podcast, and how to i change the author name?