POI 导出excel
来源:互联网 发布:软件硬件什么意思 编辑:程序博客网 时间:2024/06/05 02:46
maven依赖
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.13</version>
</dependency>
@RequestMapping(value="/export")
public void export(HttpServletResponse res) throws IOException{
List<User> allUser = dao.getAllUser();
HSSFWorkbook book=getBook(allUser);
res.setContentType("application/ms-excel;charset=UTF-8");
res.setHeader("Content-Disposition","attachment;filename=" + URLEncoder.encode("用户.xls", "UTF-8"));
OutputStream os=res.getOutputStream();
book.write(os);
os.flush();
os.close();
}
private HSSFWorkbook getBook(List<User> allUser){
HSSFWorkbook book=new HSSFWorkbook();
HSSFSheet sheet=book.createSheet("用户表");
//设置title
HSSFRow row = sheet.createRow(0);
int index=0;
setValue(row,index++,"ID");
setValue(row,index++,"用户名");
setValue(row,index++,"密码");
int dataIndex=1;
for(User u:allUser){
setData(sheet, dataIndex++,u);
}
return book;
}
private void setValue(HSSFRow row,int index,String value){
HSSFCell cell=row.createCell(index);
cell.setCellValue(value);
}
private void setData(HSSFSheet sheet,int rowindex,User u){
HSSFRow row = sheet.createRow(rowindex);
int index=0;
setValue(row,index++,String.valueOf(u.getId()));
setValue(row,index++,u.getUserName());
setValue(row,index++,u.getPassword());
}
- Excel POI导出excel
- POI-----POI导出Excel实例
- jsp导出excel poi
- POI导出EXCEL
- poi导出Excel
- poi导出excel
- POI 导出excel
- POI 导出excel
- POI 实现导出Excel
- java poi 导出excel
- poi 方式导出excel
- POI 导出Excel
- 使用poi导出excel
- poi导出excel
- poi导出excel实例
- 使用POI导出Excel
- POI 导出EXCEL
- 导出excel poi
- 笨脑壳(二)
- 微信开发专题---6微信消息处理
- [Leetcode] 29. Divide Two Integers 解题报告
- ThreadLocal 原理探究
- 别到了30岁,你变成你最讨厌的那种中年人
- POI 导出excel
- 16
- ubuntu14.04中安装opencv2.4.9
- 2037 今年暑假不AC 简单贪心算法
- 栈的内排序
- 当前上下文中不存在名称“GlobalConfiguration”
- java程序性能优化
- 进阶篇:6)公差分析
- uboot启动阶段修改启动参数方法及分析