添加导出方法
This commit is contained in:
@@ -73,6 +73,28 @@ public class ExcelUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指定名称、sheet名、title名、数据下载报表
|
||||||
|
*
|
||||||
|
* @param fileName 文件名
|
||||||
|
*/
|
||||||
|
public static void exportExcel(String fileName, String sheetName, String title, Class<?> pojoClass, Collection<?> dataSet) {
|
||||||
|
HttpServletResponse response = HttpServletUtil.getResponse();
|
||||||
|
try (ServletOutputStream outputStream = response.getOutputStream()) {
|
||||||
|
fileName = URLEncoder.encode(fileName, CharsetUtil.UTF_8);
|
||||||
|
response.reset();
|
||||||
|
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
|
||||||
|
response.setContentType("application/octet-stream;charset=UTF-8");
|
||||||
|
ExportParams exportParams = new ExportParams();
|
||||||
|
exportParams.setSheetName(sheetName);
|
||||||
|
exportParams.setTitle(title);
|
||||||
|
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, pojoClass, dataSet);
|
||||||
|
workbook.write(outputStream);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(">>> 导出数据异常:{}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 指定名称、sheet名(多个sheet)、数据(多组数据)下载报表
|
* 指定名称、sheet名(多个sheet)、数据(多组数据)下载报表
|
||||||
*
|
*
|
||||||
@@ -191,9 +213,9 @@ public class ExcelUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description:
|
|
||||||
* @param workbook
|
* @param workbook
|
||||||
* @param firstCol
|
* @param firstCol
|
||||||
|
* @Description:
|
||||||
* @Author: wr
|
* @Author: wr
|
||||||
* @Date: 2024/8/20 10:44
|
* @Date: 2024/8/20 10:44
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user