0
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
"); response.setHeader("Content-Disposition",
"attachment;filename=\"j.xls\"  ");


//int ch=Integer.parseInt(request.getParameter("id"));
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); String
url = "jdbc:sqlserver://"; Connection con =
DriverManager.getConnection(url,"sa","sql1423#3"); Statement stmt =
con.createStatement();

HSSFWorkbook hwb=new HSSFWorkbook(); HSSFSheet sheet = 
hwb.createSheet("new sheet"); HSSFSheet sheet1 =  hwb.createSheet("new
sheet1");

HSSFRow rowhead=   sheet.createRow((short)0);

String select[] = request.getParameterValues("id");  if (select != null && select.length != 0) {

    for (int i = 0; i < select.length; i++)     {   //out.println(select[i]);
        int ch=Integer.parseInt(select[i]);




        switch(ch)                  {
            case 1 :            rowhead.createCell((short) 0).setCellValue("INDEX_FLG");            ResultSet
rs=stmt.executeQuery("select INDEX_FLG from FFIX");

              while(rs.next())
              {

                  rowhead.createCell((short) 0).setCellValue(rs.getString("INDEX_FLG"));
                 //out.println(rs.getString("INDEX_FLG")); 


              }

              rs.close();
                 break;

         case 2 : 

            rowhead.createCell((short) 0).setCellValue("SYMBOL");           ResultSet rsS=stmt.executeQuery("select SYMBOL from FFIX");;

          while(rsS.next())
          {
              rowhead.createCell((short) 0).setCellValue(rsS.getString("SYMBOL"));
           } 

              rsS.close();
                break;

         case 3 : 
            rowhead.createCell((short) 0).setCellValue("SERIES");
            ResultSet rsSE=stmt.executeQuery("select SERIES from FFIX");
            while(rsSE.next())          {
                rowhead.createCell((short) 0).setCellValue(rsSE.getString("SERIES"));           
            }
         rsSE.close();
         break;
        }
    }

嗨,这是我的 jsp 代码,我正在从 html 页面检索值并检查 switch case 中的复选框值。我正在尝试使用 jsp 创建一个 excel 表并将数据库中的记录插入到该 excel 中。但是当我执行上面的代码时,它给出的输出是白色的空白 excel 文件。即使 excel 表也没有显示我现在应该做什么请帮助我 PLZ Thanx Kajal

4

1 回答 1

0

您是否将 HSSFWorkbook 写入响应的输出流?

hwb.write(response.getOutputStream())
于 2012-05-03T12:36:41.840 回答