java开发easypoi导出excel表格数据
程序员文章站
2023-11-29 17:41:04
@ApiOperation(value = "列表数据导出")@PostMapping(value = "/preFollowListExport", produces = "application/json;charset=UTF-8") public Response export(HttpServletResponse servletResponse) throws IOException { String nam....
@ApiOperation(value = "列表数据导出")
@PostMapping(value = "/preFollowListExport", produces = "application/json;charset=UTF-8")
public void export(HttpServletResponse servletResponse) throws IOException {
String name = "数据表";
servletResponse.setHeader("content-Type", "application/vnd.ms-excel");
servletResponse.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(name + ".xls", "utf-8"));
servletResponse.setHeader("Access-Control-Expose-Headers", "ContentDisposition");
//获取数据源
List<DataBean> list = null;
ExportParams params = new ExportParams(name, "sheet1");
Workbook workbook = ExcelExportUtil.exportBigExcel(params, DataBean.class, list);
ExcelExportUtil.closeExportBigExcel();
try {
workbook.write(servletResponse.getOutputStream());
}catch (IOException e) {
e.printStackTrace();
}finally {
workbook.close();
}
}
数据实体对象:
@Data
@ExcelTarget(value = "dataBean")
public class DataBean implements Serializable {
@Excel(name = "序号")
private Integer sortNum;
@Excel(name = "姓名")
private String name;
}
本文地址:https://blog.csdn.net/qq_34707456/article/details/107069917
上一篇: js每隔两秒输出数组中的一项(实例)
下一篇: PS制作猕猴桃被旋转切开的动感瞬间