Problem while opening Excel files

Discussion in 'JSP' started by priyapratheep, Apr 3, 2008.

  1. priyapratheep

    priyapratheep New Member

    Joined:
    Apr 3, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi friends

    when i try to download data from MySQL to excel sheet I am getting error of

    This file is not in a recognizable format.


    . If you know the file is from another program which is incompatible with Microsoft Office Excel,click Cancel then open this file in its original application.If you want to open the file later in Microsoft Office Excel,save it in a format that is compatible,such as text format.

    etc

    Code is
    Code:
    Class.forName("org.gjt.mm.mysql.Driver");
    Connection conn = DriverManager.getConnection("jdbc:mysql://203.116.109.81/mydb","chocku","chocku");
    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\"");

    I can open them after clicking OK, but before that it is showing the above error message

    thank you
     
    Last edited by a moderator: Apr 3, 2008

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice