pom.xml
可解决以下报错
com.alibaba.excel.exception.ExcelGenerateException: Can not close IO.
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.1.0</version>
<exclusions>
<exclusion>
<artifactId>poi-ooxml-schemas</artifactId>
<groupId>org.apache.poi</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>saxon-dom</artifactId>
<version>8.7</version>
</dependency>
模板
@Data
@Excel("运维详情记录")
@Source(name = "ip_record")
@EqualsAndHashCode
public class IpRecordXls {
@Id
/**
*
*/
@ExcelIgnore
@Column(name = "id")
public Long id;
/**
*设备id
*/
@ExcelProperty("设备id")
@Column(name = "device_id")
public Long deviceId;
/**
*运维ip
*/
@ExcelProperty("运维ip")
@Column(name = "agent_ip")
public String agentIp;
/**
*事件时间
*/
@ExcelProperty("事件时间")
@Column(name = "create_time")
public Long createTime;
/**
*事件类型
*/
@ExcelProperty("事件类型")
@Column(name = "event_type")
public String eventType;
/**
*事件描述
*/
@ExcelProperty("事件描述")
@Column(name = "event_description")
public String eventDescription;
}
@GetMapping("/IpRecordXls")
public void exportIpRecord(@RequestParam Map<String, String> params, HttpServletResponse response) throws IOException {
Map<String, String> newparams = messageAdapter.adapterQueryParams(params);
newparams.put("_limit",num.toString());
try {
List<IpRecordXls> logList = dbsvc.queryList(newparams, IpRecordXls.class);
String fileName = params.get("filePath")+params.get("titleName")+ ".xlsx";
EasyExcel.write(fileName, IpRecordXls.class).sheet("模板").doWrite(logList);
} catch (Exception e) {
e.printStackTrace();
}
}