展开全部
这个~~这个~~我只写了个查询e5a48de588b662616964757a686964616f31333234333361数据库数据生产EXCEL表的程序:
%>
} else {
Connection conn = DBConnector.getconecttion(); //得到一个数据连接
try {
String type = request.getParameter("type");
if(type==null)type="a";
String dwyhzh = (String) session.getAttribute("dwyhzh");
dwcx dwcx1 = new dwcx();
//int k = dwcx1.zgzs(conn, dwyhzh);
String sql="SELECT * FROM v_168_info WHERE dwyhzh = '" + dwyhzh + "' and zhzt!=2 ORDER BY zgyhzh asc";
if(type.equals("b")){
sql&#61; "SELECT * FROM v_168_info WHERE dwyhzh &#61; &#39;" &#43; dwyhzh &#43; "&#39; and zhzt!&#61;2 and len(sfzhm)<1 ORDER BY zgyhzh asc";
}
if(type.equals("c")){
sql&#61; "SELECT * FROM v_168_info WHERE dwyhzh &#61; &#39;" &#43; dwyhzh &#43; "&#39; and zhzt!&#61;2 and len(gjjkh)<1 ORDER BY zgyhzh asc";
}
Statement stmt &#61; conn.createStatement();
ResultSet rs &#61; stmt.executeQuery(sql);
// java.text.DecimalFormat dff &#61; new java.text.DecimalFormat(".##");
if(rs.next()) {
response.setContentType("application/vnd.ms-excel");//设置正确的输出类型
response.setHeader(" Content-Disposition ", " attachment; filename&#61;\"" &#43; dwyhzh &#43; ".xls" &#43; "\"");
HSSFWorkbook wb &#61; new HSSFWorkbook();
HSSFSheet sheet &#61; wb.createSheet("sheet1");
// 以下以写表头
// 表头为第一行
HSSFRow row &#61; sheet.createRow((short) 0);
HSSFCell cell1 &#61; row.createCell((short) 0);
HSSFCell cell2 &#61; row.createCell((short) 1);
HSSFCell cell3 &#61; row.createCell((short) 2);
HSSFCell cell4 &#61; row.createCell((short) 3);
HSSFCell cell5 &#61; row.createCell((short) 4);
HSSFCell cell6 &#61; row.createCell((short) 5);
HSSFCell cell7 &#61; row.createCell((short) 6);
HSSFCell cell8 &#61; row.createCell((short) 7);
HSSFCell cell9 &#61; row.createCell((short) 8);
HSSFCell cell10 &#61; row.createCell((short) 9);
cell1.setEncoding((short) 1);
cell1.setCellType(1);
cell2.setEncoding((short) 1);
cell2.setCellType(1);
cell3.setEncoding((short) 1);
cell3.setCellType(1);
cell4.setEncoding((short) 1);
cell4.setCellType(1);
cell5.setEncoding((short) 1);
cell5.setCellType(1);
cell6.setEncoding((short) 1);
cell6.setCellType(1);
cell7.setEncoding((short) 1);
cell7.setCellType(1);
cell8.setEncoding((short) 1);
cell8.setCellType(1);
cell9.setEncoding((short) 1);
cell9.setCellType(1);
cell10.setEncoding((short) 1);
cell10.setCellType(1);
// 定义表头的内容
cell1.setCellValue(" 单位帐号 ");
cell2.setCellValue(" 职工帐号 ");
cell3.setCellValue(" 姓名 ");
cell4.setCellValue(" 身份证 ");
cell5.setCellValue(" 卡号 ");
cell6.setCellValue(" 工资 ");
cell7.setCellValue(" 个人缴存 ");
cell8.setCellValue(" 余额 ");
cell9.setCellValue(" 缴至月份 ");
cell10.setCellValue(" 缴存状态 ");
// sheet.setColumnWidth((short)1,(short)15);
sheet.setColumnWidth((short)0,(short)3000);
sheet.setColumnWidth((short)1,(short)3000);
sheet.setColumnWidth((short)3,(short)5000);
sheet.setColumnWidth((short)4,(short)5000);
sheet.setColumnWidth((short)8,(short)3000);
int i &#61; 0;
String temp; String kkk&#61;"";
// rs.first();
while (rs.next()) {
// 定义数据从第二行开始
switch(rs.getInt("zhzt")){
case 0:kkk&#61;"停缴"; break;
case 1:kkk&#61;"缴交"; break;
case 2:kkk&#61;"销户"; break;
}
temp &#61; rs.getString("zgwym");
row &#61; sheet.createRow((short) i &#43; 1);
cell1 &#61; row.createCell((short) 0);
cell2 &#61; row.createCell((short) 1);
cell3 &#61; row.createCell((short) 2);
cell4 &#61; row.createCell((short) 3);
cell5 &#61; row.createCell((short) 4);
cell6 &#61; row.createCell((short) 5);
cell7 &#61; row.createCell((short) 6);
cell8 &#61; row.createCell((short) 7);
cell9 &#61; row.createCell((short) 8);
cell10 &#61; row.createCell((short) 9);
cell1.setEncoding((short) 1);
cell1.setCellType(1);
cell2.setEncoding((short) 1);
cell2.setCellType(1);
cell3.setEncoding((short) 1);
cell3.setCellType(1);
cell4.setEncoding((short) 1);
cell4.setCellType(1);
cell5.setEncoding((short) 1);
cell5.setCellType(1);
cell6.setEncoding((short) 1);
cell6.setCellType(1);
cell7.setEncoding((short) 1);
cell7.setCellType(1);
cell8.setEncoding((short) 1);
cell8.setCellType(1);
cell9.setEncoding((short) 1);
cell9.setCellType(1);
cell10.setEncoding((short) 1);
cell10.setCellType(1);
// 填充内容
cell1.setCellValue(rs.getString("dwyhzh"));
cell2.setCellValue(rs.getString("zgyhzh"));
cell3.setCellValue(rs.getString("zgxm"));
cell4.setCellValue(rs.getString("sfzhm"));
cell5.setCellValue(rs.getString("gjjkh"));
cell6.setCellValue(rs.getDouble("ygz"));
cell7.setCellValue(rs.getDouble("zgyje"));
cell8.setCellValue(dwcx1.zhye(conn, temp));
cell9.setCellValue(rs.getString("fsrq").substring(0,10));
cell10.setCellValue(kkk);
i&#43;&#43;;
}
wb.write(response.getOutputStream());
response.getOutputStream().flush();
response.getOutputStream().close();
}else{
%>
} stmt.close();
rs.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
DBConnector.freecon(conn); //释放数据库连接
}
}
%>
本回答被提问者采纳
已赞过
已踩过<
你对这个回答的评价是&#xff1f;
评论
收起