easyPOI单sheet页数据导出为excle

1、数据导入导出是很多管理系统都需要的一项基本功能,相对于比较easyExcle和easyPOI,用过的可能都知道,easyPOI做导出那是真的方便还好用,你想要的姿势,‘她’都可以实现。话不多说上代码:先来单个sheet页导出(pom依赖官网就有,为什么要这样写呢,因为,官网有点吸引人,功能太多值得一看:http://doc.wupaas.com/docs/easypoi/easypoi-1c0u9dt0lqnpl

注解实体参数:

@Excel(name = "excle表头名", height = 20, width = 30)
private String contructionStatusName;
@Excel(name = "日期格式化", height = 20, width = 30, databaseFormat = "yyyy-MM-dd", format = "yyyy-MM-dd")
private String enterFactoryTime;
@Excel(name = 数字格式化", height = 20, width = 30, numFormat = "0.00") 保留两位小数
private BigDecimal num;

 

/**
 * 导出
 * @param response
 * @param list 到处数据源
 * @param fileName
 * @param object 注解类实体
 */
public  static void exportDefault(HttpServletResponse response, List<?> list, String fileName, Object object, String sheetName){
    Workbook workbook = new XSSFWorkbook();
    workbook = ExcelExportUtil.exportExcel(new ExportParams(fileName, sheetName), object.getClass(),list);
    if (workbook != null) {
        downLoadExcel(fileName, response, workbook);
    }
}

 

/**
 * 功能描述:Excel导出
 *
 * @param fileName 文件名称
 * @param response 将流数据导出到前端
 * @param workbook Excel对象
 * @return
 */
private static void downLoadExcel(String fileName, HttpServletResponse response, Workbook workbook) {
    try {
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/vnd.ms-excel;charset=utf-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName + "." + ExcelTypeEnum.XLSX.getValue(), "UTF-8"));
        workbook.write(response.getOutputStream());
    } catch (IOException e) {
        throw new  RuntimeException(e);
    }
}

 

 

 

接下来请关注多sheet页导出

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值