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代碼,我retriving從HTML頁面和複選框在開關辦案。我試圖創建一個使用JSP的Excel工作表的值檢查值和將數據庫中的記錄插入到該excel中。但是當我執行上面的代碼給白空白輸出練成file..even Excel表,也沒有顯示 我現在應該怎麼辦 plz幫助我 PLZ 感謝名單 Kajal創建一個Excel工作表,並從數據庫中插入數據
你我已經寫了每一個開關的情況下,但它只打印一個記錄.....你有什麼想法嗎? – user1372442
ResultSet rs = stmt.executeQuery(「從FFIX中選擇INDEX_FLG」); rowhead.createCell((short)i).setCellValue(「INDEX_FLG」); \t \t \t而(rs.next()) \t \t \t {rowhead.createCell((短)ⅰ).setCellValue(rs.getString( 「INDEX_FLG」)); \t \t \t \t hwb.write(response.getOutputStream()); \t \t \t \t \t \t \t} \t \t \t我寫了這樣的.......但它打印在Excel工作表中只有一條記錄 – user1372442
你應該寫工作簿中只有一次的反應(即' hwb.write(response.getOutputStream())')。在結束處理結果集和更新工作簿時,應該在方法結束時執行此操作。 – bpgergo