六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 48|回复: 0

web导出Excel例子

[复制链接]

升级  46%

5

主题

5

主题

5

主题

童生

Rank: 1

积分
23
 楼主| 发表于 2013-1-28 18:57:31 | 显示全部楼层 |阅读模式
List<String> list = new ArrayList<String>();
list.add("test1~test2");
try {
HSSFWorkbook workbook = new HSSFWorkbook();

HSSFSheet sheet = workbook.createSheet();
for (int index = 0; index < list.size(); index++) {
HSSFRow row = sheet.createRow((short) index);

String[] temp = ((String) list.get(index)).split("~");

HSSFRichTextString rtString = null;

HSSFCell cell = null;

if (temp.length > 0) {
cell = row.createCell((short) 0);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
rtString = new HSSFRichTextString(temp[0]);
cell.setCellValue(rtString);
}

if (temp.length > 1) {
cell = row.createCell((short) 1);
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
rtString = new HSSFRichTextString(temp[1]);
cell.setCellValue(rtString);
}
}
OutputStream os = response.getOutputStream();
response.setBufferSize(1000000);
            workbook.write(os);
} catch (Exception e) {
e.printStackTrace();
}
response.setContentType("application/vnd.ms-excel;charset=utf-8");
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("Export", "UTF-8") + ".xls");
return null;
}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表