0
点赞
收藏
分享

微信扫一扫

EasyExcel 自定义标题导出

月白色的大狒 03-01 12:45 阅读 3

  public void exportList( HttpServletResponse response) {
    response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
           response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");

//组装表头
List<List<String>> headList = Lists.newLinkedList();
headList.add(Collections.singletonList("标题1"));
headList.add(Collections.singletonList("标题2"));
headList.add(Collections.singletonList("标题3"));

 //内容
  List<List<String>> dataList = Lists.newLinkedList();
        dataList.add(Collections.singletonList("内容1"));
        dataList.add(Collections.singletonList("内容2"));
        dataList.add(Collections.singletonList("内容3"));
//标题行  与  内容一一对应

EasyExcel.write(response.getOutputStream())
        .head(headList)
        .autoCloseStream(Boolean.TRUE)
        .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) //自动列宽
        .sheet("sheet1")
        .doWrite(dataList);
        
        )

举报

相关推荐

0 条评论