easyExcel导出excel文件 前后端代码

网上太多啥吊只给出后端有个屌用,自己看了很多文章最后搞出来了,给大家参考。

官方文档

https://www.yuque.com/easyexcel/doc/write

 

https://blog.csdn.net/u010957645/article/details/101362194

 

https://github.com/a81579261/demo/blob/master/src/main/java/com/example/demo/handler/MySheetWriteHandler.java

 

导出

@RequestMapping("/download3")
public void download(HttpServletResponse response,String rfxCode) throws Exception {
    response.setContentType("application/vnd.ms-excel");
    response.setCharacterEncoding("utf-8");
    String fileName = URLEncoder.encode("核价", "UTF-8");
    response.setHeader("Content-disposition", "attachment;filename="+fileName+".xlsx");
    List<CheckPriceDto> list=purRfxHeadersService.selectList("RFQ2021020100024");
    //获取所有的报价的信息
    EasyExcel.write(response.getOutputStream(), CheckPriceDto.class).sheet("核价").doWrite(list);
}


import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.metadata.BaseRowModel;

public class CheckPriceDto extends BaseRowModel {
@ExcelProperty(value = "物品编码", index = 0)
private String itemCode;
@ExcelProperty(value = "物品名称", index = 1)
private String itemName;
@ExcelProperty(value = "供应商编码", index = 2)
private String vendorCode;
@ExcelProperty(value = "供应商名称", index = 3)
private String vendorName;
@ExcelProperty(value = "策略(推荐供应商,取消询价,完成询价)", index = 4)
private String strategy;
@ExcelProperty(value = "是否选用(是,否)", index = 5)
private String flag;
}


jQ前端点击事件

 

function pur51302_rfxLnItemsExport(){
var form = document.createElement('form');
form.id = 'form';
form.name = 'form';
//把这个form放在body里面
document.body.appendChild(form);
form.method = "post"
form.action = '/api/rest/v1/pur/download3';
form.submit();
document.body.removeChild(form)
}

 

 

 

Guess you like

Origin blog.csdn.net/liangdingguo/article/details/115606810