优化代码
This commit is contained in:
parent
bd1595331b
commit
32a16c753f
|
@ -137,12 +137,7 @@ public class ExcelUtils {
|
|||
*/
|
||||
public static <T> void excelExport(Class<T> head, String excelName, String sheetName, List<T> data) {
|
||||
try {
|
||||
HttpServletResponse response = HttpContextUtils.getHttpServletResponse();
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
String fileName = URLUtil.encode(excelName, StandardCharsets.UTF_8);
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
||||
HttpServletResponse response = getExportResponse(excelName);
|
||||
|
||||
EasyExcel.write(response.getOutputStream(), head).sheet(StringUtils.isBlank(sheetName) ? "sheet1" : sheetName).doWrite(data);
|
||||
} catch (IOException e) {
|
||||
|
@ -161,12 +156,7 @@ public class ExcelUtils {
|
|||
*/
|
||||
public static <T> void excelExport(List<List<String>> head, String excelName, String sheetName, List<T> data) {
|
||||
try {
|
||||
HttpServletResponse response = HttpContextUtils.getHttpServletResponse();
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
String fileName = URLUtil.encode(excelName, StandardCharsets.UTF_8);
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
||||
HttpServletResponse response = getExportResponse(excelName);
|
||||
|
||||
EasyExcel.write(response.getOutputStream()).head(head).sheet(StringUtils.isBlank(sheetName) ? "sheet1" : sheetName).doWrite(data);
|
||||
} catch (IOException e) {
|
||||
|
@ -174,6 +164,17 @@ public class ExcelUtils {
|
|||
}
|
||||
}
|
||||
|
||||
private static HttpServletResponse getExportResponse(String excelName) {
|
||||
HttpServletResponse response = HttpContextUtils.getHttpServletResponse();
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
String fileName = URLUtil.encode(excelName, StandardCharsets.UTF_8);
|
||||
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析字典数据到字段上
|
||||
* 比如 T中有 genderLabel字段 为男 需要给 gender 字段自动设置为0
|
||||
|
|
Loading…
Reference in New Issue
Block a user