easypoi导出Excel
来源:互联网 发布:网络咨询师工作流程 编辑:程序博客网 时间:2024/06/08 01:52
本例使用的easypoi包是easypoi-0.2-fix.jar
前端调用方式和其他(poi,jxl等)一致,此处暂不记录。
java导出代码如下:
1.User实体
public class User {private int userId;private String name;private String sex;private String address; public int getUserId() {return userId;}public void setUserId(int userId) {this.userId = userId;}public String getName() {return name;}public void setName(String name) {this.name = name;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public String getAddress() {return address;}public void setAddress(String address) {this.address = address;}}
2.导出调用方法
/** * 导出Excel */public void exportUserInfoToExcel() throws IOException{OutputStream out = response.getOutputStream();response.setContentType("application/x-download");//设置导出文件名称response.setHeader("Content-Disposition", "attachment;filename="+DateUtil.getNow("yyyyMMddHHmmssSSS")+".xls");Excel excel = new Excel();//查询内容list,userService.getUserList方法自己实现List<User> list = userService.getUserList();//表头数组String[] header = {"用户ID","用户名","性别","地址"};//表单titleString title = "用户信息列表";int headerLen = header.length;//单元格边框颜色Color borderColor = Color.GREY_50_PERCENT;//表头字体IFontEditor headFont = new IFontEditor(){public void updateFont(Font font){font.fontHeightInPoints(14).boldweight(BoldWeight.BOLD).color(Color.WHITE);}};//标题字体IFontEditor titleFont = new IFontEditor(){public void updateFont(Font font){font.fontHeightInPoints(30).boldweight(BoldWeight.BOLD) .color(Color.DARK_BLUE);}};//设置表单信息excel.setWorkingSheet(0)//设置第1个工作表为工作状态 .sheetName(title+"1") .fitToPage(true) .horizontallyCenter(true) .printGridlines(false) .displayGridlines(true) .autobreaks(true) .printSetup(new IPrintSetup(){public void setup(HSSFPrintSetup printSetup) {printSetup.setLandscape(true);//是否打印背景printSetup.setFitHeight((short)1);//调整缩放 printSetup.setFitWidth((short)1);//调整缩放} });//设置标题内容,标题行列合并,标题样式excel.row(0).height(60); excel.cell(0, 0).value(title) .align(Align.CENTER) .font(titleFont); excel.region(0, 0, 0, headerLen-1).merge();//合并标题的单元格 //设置表头及样式 for(int i=0;i<headerLen;i++){ excel.column(i).width(5000); excel.cell(1, i).value(header[i]) .align(Align.CENTER) .bgColor(Color.DARK_BLUE) .font(headFont); } //添加内容 for(int i=0,len=list.size();i<len;i++){ excel.row(i+2).height(30);//设置行高度 for(int j=0;j<headerLen;j++){ excel.cell(i+2, j).align(Align.CENTER)//设置区域内单元格水平对齐方式 .vAlign(VAlign.CENTER)//设置垂直对齐方式 .border(BorderStyle.THIN, borderColor); } User grid = list.get(i); excel.cell(i+2, 0).value(grid.getUserId()); excel.cell(i+2, 1).value(grid.getName()); excel.cell(i+2, 2).value(grid.getSex()); excel.cell(i+2, 3).value(grid.getAddress()); } excel.saveExcel(out);}
3.打印横向设置
//设置横向打印IPrintSetup printSetup = new IPrintSetup(){public void setup(HSSFPrintSetup setup) {setup.setLandscape(true);}};excel.setWorkingSheet(0).printSetup(printSetup);
0 0
- easypoi导出Excel
- springboot easypoi导出excel
- Easypoi模版导出excel
- java easypoi导出Excel表格
- 关于easyPOI导出Excel功能
- easypoi-springboot/springmvc导出数据为Excel
- EasyPoi 模板语法介绍,POI 的Excel模板导出
- Spring Boot 菜鸟教程 12 EasyPoi导出Excel下载
- EasyPOI->模版形式导出Excel(多Sheet)
- SpringMVC/SpringBoot使用easypoi实现Excel文件导入导出功能实现
- 【工具篇】Excel文件导出从未如此简单——EasyPOI的使用
- EasyPoi 如何筛选导出属性
- EasyPOI
- [EasyPoi] 初识EasyPoi
- easyPoi学习
- [EasyPoi] Easypoi介绍,以及入门
- 导出EXCEL
- Excel导出
- 用VS编译出可独立运行的程序
- 图说微积分(三)函数
- J-LINK7 固件修复
- NYOJ 163 Phone List
- 无法获取未定义或null引用的属性“style”
- easypoi导出Excel
- synchronized 介绍
- LibUsbDotNet使用方法
- Eclipse Class Decompiler——Java反编译插件
- Linux 之 export 本质
- 用绘本回忆青春创业经历——leo鉴书46
- 深搜之搜索树
- 视频捕捉代码
- OCP-1Z0-053-V13.02-502题