//从jsp页面中获取多个Id
String ids = request.getParameter("ids");
System.out.println(ids);
//从数据库中查询到要导出的字段信息
List<News> news = n.inputExecl(ids);
System.out.println(news.toString());
//第一步:创建工作部对象
HSSFWorkbook work=new HSSFWorkbook();
//第二步:创建工作表对象
HSSFSheet table=work.createSheet("新闻信息表");
//第三步:设置行标题
String[] title=new String[]{"ID","信息标题","发布时间","更新时间","是否推荐"};
//遍历所查询到的信息
HSSFRow smallRow = table.createRow(0);
for(int i=0;i<title.length;i++){
HSSFCell createCell = smallRow.createCell(i);
createCell.setCellValue(title[i]);
}
//第四步:遍历集合对象
for(int i=0;i<news.size();i++){
News n=news.get(i);
//创建行
HSSFRow row = table.createRow(i+1);//因为java数数是从0开始的,每遍历一次要加1
// 开始创建单元格并赋值
HSSFCell ns_idCell = row.createCell(0);
ns_idCell.setCellValue(n.getNs_id());
HSSFCell ns_titleCell = row.createCell(1);
ns_titleCell.setCellValue(n.getNs_title());
HSSFCell ns_showtimeCell = row.createCell(2);
ns_showtimeCell.setCellValue(n.getNs_showtime());
HSSFCell ns_updateCell = row.createCell(3);
ns_updateCell.setCellValue(n.getNs_update());
HSSFCell ns_stateCell = row.createCell(4);
ns_stateCell.setCellValue(n.getNs_state());
}
//第五步:生产Excel文件名
String ExcelName ="账单管理基础信息表" + ".xlsx";
//下载功能
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(ExcelName, "utf-8"));
ServletOutputStream out = response.getOutputStream();
work.write(out);
out.close();// 关闭流
String ids = request.getParameter("ids");
System.out.println(ids);
//从数据库中查询到要导出的字段信息
List<News> news = n.inputExecl(ids);
System.out.println(news.toString());
//第一步:创建工作部对象
HSSFWorkbook work=new HSSFWorkbook();
//第二步:创建工作表对象
HSSFSheet table=work.createSheet("新闻信息表");
//第三步:设置行标题
String[] title=new String[]{"ID","信息标题","发布时间","更新时间","是否推荐"};
//遍历所查询到的信息
HSSFRow smallRow = table.createRow(0);
for(int i=0;i<title.length;i++){
HSSFCell createCell = smallRow.createCell(i);
createCell.setCellValue(title[i]);
}
//第四步:遍历集合对象
for(int i=0;i<news.size();i++){
News n=news.get(i);
//创建行
HSSFRow row = table.createRow(i+1);//因为java数数是从0开始的,每遍历一次要加1
// 开始创建单元格并赋值
HSSFCell ns_idCell = row.createCell(0);
ns_idCell.setCellValue(n.getNs_id());
HSSFCell ns_titleCell = row.createCell(1);
ns_titleCell.setCellValue(n.getNs_title());
HSSFCell ns_showtimeCell = row.createCell(2);
ns_showtimeCell.setCellValue(n.getNs_showtime());
HSSFCell ns_updateCell = row.createCell(3);
ns_updateCell.setCellValue(n.getNs_update());
HSSFCell ns_stateCell = row.createCell(4);
ns_stateCell.setCellValue(n.getNs_state());
}
//第五步:生产Excel文件名
String ExcelName ="账单管理基础信息表" + ".xlsx";
//下载功能
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(ExcelName, "utf-8"));
ServletOutputStream out = response.getOutputStream();
work.write(out);
out.close();// 关闭流