List beanList = mcReportUserService.findList(queryString, values);// .findAll();
// response.setContentType("octets/stream");
response.setContentType("application/msexcel");// 定义输出类型
response.addHeader("Content-Disposition", "attachment;filename=test.xls"); //测试图书 ExportExcel ex = new ExportExcel();
// workbook = new HSSFWorkbook();
String[] headers = {"编号", "时间", "商户名称", "任务类型", "类别", "等级","联系人" ,"职务", "联系方式", "地址", "进度", "后续跟踪方式","下次跟踪时间","备注"};
//List<Book> dataset = new ArrayList<Book>();
OutputStream out = response.getOutputStream();
// WritableWorkbook
HSSFWorkbook workbook= ex.exportExcel(headers, beanList, out); // response.setContentType(getContentType());
ServletOutputStream outs = response.getOutputStream();
workbook.write(outs);
outs.flush();
// try {
// workbook.write(out);
// out.flush();
// System.out.println("excel导出成功!");
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// response.setContentType("octets/stream");
response.setContentType("application/msexcel");// 定义输出类型
response.addHeader("Content-Disposition", "attachment;filename=test.xls"); //测试图书 ExportExcel ex = new ExportExcel();
// workbook = new HSSFWorkbook();
String[] headers = {"编号", "时间", "商户名称", "任务类型", "类别", "等级","联系人" ,"职务", "联系方式", "地址", "进度", "后续跟踪方式","下次跟踪时间","备注"};
//List<Book> dataset = new ArrayList<Book>();
OutputStream out = response.getOutputStream();
// WritableWorkbook
HSSFWorkbook workbook= ex.exportExcel(headers, beanList, out); // response.setContentType(getContentType());
ServletOutputStream outs = response.getOutputStream();
workbook.write(outs);
outs.flush();
// try {
// workbook.write(out);
// out.flush();
// System.out.println("excel导出成功!");
// } catch (Exception e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
解决方案 »
- javaEE开发,javaBean代码模拟登录各种站点
- 求助:An unexpected error has been detected by HotSpot Virtual Machine:
- 谁能给我一个hibernate插件??
- Hibernate: 为何查出来的结果始终是数据库中的第一条记录? ..在线等...急..
- axis在linux下的发布!!
- 在struts框架下在jsp页面中引入一个Action报错
- 十万火急!在线等 tomcat 问题 高分
- 碰到了一个奇怪问题,请帮忙.
- hibernate 一对一 两边都允许为空 怎么配置注解
- struts2的convention插件问题
- -- * 求助 2011.11.7 * -- 关于 HttpClient 和 Cookie 的问题。
- 如何将一串数字转换为日期
public static void writeExcel(OutputStream out, List<String[]> beanList)
throws Exception {
HSSFWorkbook book = new HSSFWorkbook();
HSSFSheet sheet = book.createSheet(bean.getSheetName()); for(int i = 0; i < beanList.size(); i++) {
HSSFRow row = sheet.createRow(sheet.getLastRowNum());
String data = beanList.get(i); for(int j = 0; j < data.length; j++) {
HSSFCell cell = row.createCell(j);
cell.setCellValue(data[j]);
}
} book.write(out);
}