diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java index 885381bc3..402c4e85b 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java @@ -91,6 +91,25 @@ public class ExcelUtil { } } + /** + * 导出excel + * + * @param list 导出数据集合 + * @param sheetName 工作表的名称 + * @param clazz 实体类 + * @param response 响应体 + * @param options 级联下拉选 + */ + public static void exportExcel(List list, String sheetName, Class clazz, HttpServletResponse response, List options) { + try { + resetResponse(sheetName, response); + ServletOutputStream os = response.getOutputStream(); + exportExcel(list, sheetName, clazz, false, os, options); + } catch (IOException e) { + throw new RuntimeException("导出Excel异常"); + } + } + /** * 导出excel * @@ -111,25 +130,20 @@ public class ExcelUtil { } /** - * 导出带有下拉框的Excel表格 + * 导出excel * - * @param options 下拉框数据 + * @param list 导出数据集合 + * @param sheetName 工作表的名称 + * @param clazz 实体类 + * @param merge 是否合并单元格 + * @param response 响应体 + * @param options 级联下拉选 */ - public static void exportExcel(List list, String sheetName, Class clazz, - HttpServletResponse response, List options) { + public static void exportExcel(List list, String sheetName, Class clazz, boolean merge, HttpServletResponse response, List options) { try { resetResponse(sheetName, response); ServletOutputStream os = response.getOutputStream(); - ExcelWriterSheetBuilder builder = EasyExcel.write(os, clazz) - .autoCloseStream(false) - // 自动适配 - .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) - // 大数值自动转换 防止失真 - .registerConverter(new ExcelBigNumberConvert()) - // 添加下拉框操作 - .registerWriteHandler(new ExcelDownHandler(options)) - .sheet(sheetName); - builder.doWrite(list); + exportExcel(list, sheetName, clazz, merge, os, options); } catch (IOException e) { throw new RuntimeException("导出Excel异常"); } @@ -147,6 +161,19 @@ public class ExcelUtil { exportExcel(list, sheetName, clazz, false, os); } + /** + * 导出excel + * + * @param list 导出数据集合 + * @param sheetName 工作表的名称 + * @param clazz 实体类 + * @param os 输出流 + * @param options 级联下拉选内容 + */ + public static void exportExcel(List list, String sheetName, Class clazz, OutputStream os, List options) { + exportExcel(list, sheetName, clazz, false, os, options); + } + /** * 导出excel * @@ -177,7 +204,7 @@ public class ExcelUtil { * @param options 下拉框数据 */ public static void exportExcel(List list, String sheetName, Class clazz, - OutputStream os, List options) { + boolean merge, OutputStream os, List options) { ExcelWriterSheetBuilder builder = EasyExcel.write(os, clazz) .autoCloseStream(false) // 自动适配 @@ -187,6 +214,10 @@ public class ExcelUtil { // 添加下拉框操作 .registerWriteHandler(new ExcelDownHandler(options)) .sheet(sheetName); + if (merge) { + // 合并处理器 + builder.registerWriteHandler(new CellMergeStrategy(list, true)); + } builder.doWrite(list); }