pom
<!--导入导出依赖-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.1.3</version>
</dependency>
代码
* 下载vin和焊点编号的温度,电流,电阻数据
* @return
*/
public ReturnObject download(HttpServletResponse response,String vin, String solderPointId){
// 要导出的数据
List<GraphAllVo> solderPointIdGraphAll = solderPointService.getSolderPointIdGraphAll(vin, solderPointId);
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
try {
String fileName = null;
fileName = URLEncoder.encode("xlsx名","UTF-8");
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
EasyExcel.write(response.getOutputStream(),GraphAllVo.class)
.sheet("honda")
.doWrite(solderPointIdGraphAll);
} catch (IOException e) {
log.error("导出失败",e);
return ReturnObject.error("400","导出失败: " + e.getMessage());
}
return ReturnObject.success();
}
实体类
@Data
@AllArgsConstructor
@NoArgsConstructor
@Api(tags = "折线图字段说明")
public class GraphAllVo {
// index 是列顺序 从0开始 , value 是xlsx 每一列的名字
@ApiModelProperty("时间")
@ExcelProperty(index = 3, value = "时间")
private String time;
@ApiModelProperty("电阻")
@ExcelProperty(index = 2, value = "电阻")
private String current;
@ApiModelProperty("电流")
@ExcelProperty(index = 1, value = "电流")
private String resistance;
@ApiModelProperty("温度")
@ExcelProperty(index = 0, value = "温度")
private String heat;
}
该文章是 个人的笔记 如有不妥 望指正 谢谢