POI导出

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();
}
}

posted @ 2016-06-12 09:54  N神3  阅读(129)  评论(0编辑  收藏  举报