<%@ page contentType="application/vnd.ms-excel;charset=gbk" language="java" %>
<%@ page import="java.io.*"%>
<%@ page import="java.sql.ResultSet"%>
<%@ page import="com.jc.dao.*"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFCell"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFRow"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFSheet"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%
String d1 = request.getParameter("d1");
String d2 = request.getParameter("d2");
%>
<%
//response.reset();
response.setContentType( "APPLICATION/OCTET-STREAM" );
response.setHeader("Content-Disposition", "attachment;filename=UserInfo.xls");
//OutputStream os=response.getOutputStream();
%>
<%
HSSFWorkbook wb = new HSSFWorkbook();
// 使用默认的构造方法创建workbook
//FileOutputStream fileOut = new FileOutputStream("workbook.xls");
// 指定文件名
//创建一个sheet
HSSFSheet sheet1 = wb.createSheet("new sheet");
// workbook创建sheet
HSSFSheet sheet2 = wb.createSheet("second sheet");
// workbook创建另外的sheet
//创建cells
// 注意以下的代码很多方法的参数是short 而不是int 所以需要做一次类型转换
HSSFRow row = sheet1.createRow((short)0);
// sheet 创建一行
HSSFCell cell = row.createCell((short)0);
// 行创建一个单元格
cell.setCellValue("ID");
// 设定单元格的值
// 值的类型参数有多中double ,String ,boolean,
row.createCell((short)1).setCellValue("用户名");
row.createCell((short)2).setCellValue("姓名");
row.createCell((short)3).setCellValue("性别");
row.createCell((short)4).setCellValue("邮箱");
row.createCell((short)5).setCellValue("电话");
row.createCell((short)6).setCellValue("卡号");
row.createCell((short)7).setCellValue("积分");
row.createCell((short)8).setCellValue("身份证");
row.createCell((short)9).setCellValue("联系地址");
row.createCell((short)10).setCellValue("手机号码");
Service s = new Service();
ResultSet rs = s.queryByTime(d1, d2);
int i =1;
while(rs.next()){
row = sheet1.createRow((short)i);
// sheet 创建一行
cell = row.createCell((short)0);
// 行创建一个单元格
cell.setCellValue(rs.getInt("id"));
// 设定单元格的值
// 值的类型参数有多中double ,String ,boolean,
row.createCell((short)1).setCellValue(rs.getString("Name"));
row.createCell((short)2).setCellValue(rs.getString("Xm"));
row.createCell((short)3).setCellValue(rs.getInt("Xb"));
row.createCell((short)4).setCellValue(rs.getString("Email"));
row.createCell((short)5).setCellValue(rs.getString("Lxdh"));
row.createCell((short)6).setCellValue(rs.getString("Card"));
row.createCell((short)7).setCellValue(rs.getInt("Score"));
row.createCell((short)8).setCellValue(rs.getString("Sfzh"));
row.createCell((short)9).setCellValue(rs.getString("Mqjzd"));
row.createCell((short)10).setCellValue(rs.getString("mobi"));
i++;
}
//wb.write(fileOut);
rs.close();
wb.write(response.getOutputStream());
response.getOutputStream().flush();
response.getOutputStream().close();
// 输出到文件
//fileOut.close();
%>