码迷,mamicode.com
首页 > 其他好文 > 详细

POI导出

时间:2016-06-12 10:41:42      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:

public void export(){
try {
String columns = getPara("nameArray");
List<Record> list = SimpleService.export(columns);
HSSFWorkbook wb = new HSSFWorkbook(); //创建excel文件
HSSFSheet sheet = wb.createSheet(); //创建工作单
String[] columnArray = columns.split(",");
this.exportHeader(sheet, columns); //创建表头
for(int i =0;i<list.size();i++){
Record record = list.get(i);
HSSFRow row = sheet.createRow(i+1);
for(int j = 0;j<columnArray.length;j++){
String column = columnArray[j].split("\\.")[1];
HSSFCell cell = row.createCell(j);
if(record.get(column)!=null){
cell.setCellValue(record.get(column).toString());
}
}
}
OutputStream outputStream = getResponse().getOutputStream();
getResponse().setHeader("content-disposition", "attachment;filename="+ new String("月销售数据.xls".getBytes("gb2312"), "iso8859-1"));
wb.write(outputStream);
} catch (IOException e) {
e.printStackTrace();
}
}

POI导出

标签:

原文地址:http://www.cnblogs.com/chenweichu/p/5576661.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!