feat(excel): 为 ExcelUtil 类的 exportExcel 方法添加排除列功能
This commit is contained in:
parent
ea50a57602
commit
4e6077cb7c
@ -77,15 +77,16 @@ public class ExcelUtil {
|
||||
* 导出excel
|
||||
*
|
||||
* @param list 导出数据集合
|
||||
* @param excludeColumnFieldNames 排除的列字段名称集合
|
||||
* @param sheetName 工作表的名称
|
||||
* @param clazz 实体类
|
||||
* @param response 响应体
|
||||
*/
|
||||
public static <T> void exportExcel(List<T> list, String sheetName, Class<T> clazz, HttpServletResponse response) {
|
||||
public static <T> void exportExcel(List<T> list, Collection<String> excludeColumnFieldNames, String sheetName, Class<T> clazz, HttpServletResponse response) {
|
||||
try {
|
||||
resetResponse(sheetName, response);
|
||||
ServletOutputStream os = response.getOutputStream();
|
||||
exportExcel(list, sheetName, clazz, false, os, null);
|
||||
exportExcel(list, excludeColumnFieldNames, sheetName, clazz, false, os, null);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("导出Excel异常");
|
||||
}
|
||||
@ -95,16 +96,17 @@ public class ExcelUtil {
|
||||
* 导出excel
|
||||
*
|
||||
* @param list 导出数据集合
|
||||
* @param excludeColumnFieldNames 排除的列字段名称集合
|
||||
* @param sheetName 工作表的名称
|
||||
* @param clazz 实体类
|
||||
* @param response 响应体
|
||||
* @param options 级联下拉选
|
||||
*/
|
||||
public static <T> void exportExcel(List<T> list, String sheetName, Class<T> clazz, HttpServletResponse response, List<DropDownOptions> options) {
|
||||
public static <T> void exportExcel(List<T> list, Collection<String> excludeColumnFieldNames, String sheetName, Class<T> clazz, HttpServletResponse response, List<DropDownOptions> options) {
|
||||
try {
|
||||
resetResponse(sheetName, response);
|
||||
ServletOutputStream os = response.getOutputStream();
|
||||
exportExcel(list, sheetName, clazz, false, os, options);
|
||||
exportExcel(list, excludeColumnFieldNames, sheetName, clazz, false, os, options);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("导出Excel异常");
|
||||
}
|
||||
@ -114,16 +116,17 @@ public class ExcelUtil {
|
||||
* 导出excel
|
||||
*
|
||||
* @param list 导出数据集合
|
||||
* @param excludeColumnFieldNames 排除的列字段名称集合
|
||||
* @param sheetName 工作表的名称
|
||||
* @param clazz 实体类
|
||||
* @param merge 是否合并单元格
|
||||
* @param response 响应体
|
||||
*/
|
||||
public static <T> void exportExcel(List<T> list, String sheetName, Class<T> clazz, boolean merge, HttpServletResponse response) {
|
||||
public static <T> void exportExcel(List<T> list, Collection<String> excludeColumnFieldNames, String sheetName, Class<T> clazz, boolean merge, HttpServletResponse response) {
|
||||
try {
|
||||
resetResponse(sheetName, response);
|
||||
ServletOutputStream os = response.getOutputStream();
|
||||
exportExcel(list, sheetName, clazz, merge, os, null);
|
||||
exportExcel(list, excludeColumnFieldNames, sheetName, clazz, merge, os, null);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("导出Excel异常");
|
||||
}
|
||||
@ -133,17 +136,18 @@ public class ExcelUtil {
|
||||
* 导出excel
|
||||
*
|
||||
* @param list 导出数据集合
|
||||
* @param excludeColumnFieldNames 排除的列字段名称集合
|
||||
* @param sheetName 工作表的名称
|
||||
* @param clazz 实体类
|
||||
* @param merge 是否合并单元格
|
||||
* @param response 响应体
|
||||
* @param options 级联下拉选
|
||||
*/
|
||||
public static <T> void exportExcel(List<T> list, String sheetName, Class<T> clazz, boolean merge, HttpServletResponse response, List<DropDownOptions> options) {
|
||||
public static <T> void exportExcel(List<T> list, Collection<String> excludeColumnFieldNames, String sheetName, Class<T> clazz, boolean merge, HttpServletResponse response, List<DropDownOptions> options) {
|
||||
try {
|
||||
resetResponse(sheetName, response);
|
||||
ServletOutputStream os = response.getOutputStream();
|
||||
exportExcel(list, sheetName, clazz, merge, os, options);
|
||||
exportExcel(list, excludeColumnFieldNames, sheetName, clazz, merge, os, options);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("导出Excel异常");
|
||||
}
|
||||
@ -153,42 +157,48 @@ public class ExcelUtil {
|
||||
* 导出excel
|
||||
*
|
||||
* @param list 导出数据集合
|
||||
* @param excludeColumnFieldNames 排除的列字段名称集合
|
||||
* @param sheetName 工作表的名称
|
||||
* @param clazz 实体类
|
||||
* @param os 输出流
|
||||
*/
|
||||
public static <T> void exportExcel(List<T> list, String sheetName, Class<T> clazz, OutputStream os) {
|
||||
exportExcel(list, sheetName, clazz, false, os, null);
|
||||
public static <T> void exportExcel(List<T> list, Collection<String> excludeColumnFieldNames, String sheetName, Class<T> clazz, OutputStream os) {
|
||||
exportExcel(list, excludeColumnFieldNames, sheetName, clazz, false, os, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param list 导出数据集合
|
||||
* @param excludeColumnFieldNames 排除的列字段名称集合
|
||||
* @param sheetName 工作表的名称
|
||||
* @param clazz 实体类
|
||||
* @param os 输出流
|
||||
* @param options 级联下拉选内容
|
||||
*/
|
||||
public static <T> void exportExcel(List<T> list, String sheetName, Class<T> clazz, OutputStream os, List<DropDownOptions> options) {
|
||||
exportExcel(list, sheetName, clazz, false, os, options);
|
||||
public static <T> void exportExcel(List<T> list, Collection<String> excludeColumnFieldNames, String sheetName, Class<T> clazz, OutputStream os, List<DropDownOptions> options) {
|
||||
exportExcel(list, excludeColumnFieldNames, sheetName, clazz, false, os, options);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param list 导出数据集合
|
||||
* @param excludeColumnFieldNames 排除的列字段名称集合
|
||||
* @see com.alibaba.excel.write.builder.AbstractExcelWriterParameterBuilder#excludeColumnFieldNames(java.util.Collection)
|
||||
* @param sheetName 工作表的名称
|
||||
* @param clazz 实体类
|
||||
* @param merge 是否合并单元格
|
||||
* @param os 输出流
|
||||
*/
|
||||
public static <T> void exportExcel(List<T> list, String sheetName, Class<T> clazz, boolean merge,
|
||||
public static <T> void exportExcel(List<T> list, Collection<String> excludeColumnFieldNames, String sheetName, Class<T> clazz, boolean merge,
|
||||
OutputStream os, List<DropDownOptions> options) {
|
||||
ExcelWriterSheetBuilder builder = EasyExcel.write(os, clazz)
|
||||
.autoCloseStream(false)
|
||||
// 自动适配
|
||||
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
|
||||
// 忽略自定义列
|
||||
.excludeColumnFieldNames(excludeColumnFieldNames)
|
||||
// 大数值自动转换 防止失真
|
||||
.registerConverter(new ExcelBigNumberConvert())
|
||||
.sheet(sheetName);
|
||||
|
@ -92,7 +92,7 @@ public class TestDemoController extends BaseController {
|
||||
// for (TestDemoVo vo : list) {
|
||||
// vo.setId(1234567891234567893L);
|
||||
// }
|
||||
ExcelUtil.exportExcel(list, "测试单表", TestDemoVo.class, response);
|
||||
ExcelUtil.exportExcel(list,List.of("用户id"), "测试单表", TestDemoVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@ -55,7 +56,7 @@ public class TestTreeController extends BaseController {
|
||||
@GetMapping("/export")
|
||||
public void export(@Validated TestTreeBo bo, HttpServletResponse response) {
|
||||
List<TestTreeVo> list = testTreeService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "测试树表", TestTreeVo.class, response);
|
||||
ExcelUtil.exportExcel(list, null, "测试树表", TestTreeVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,7 +98,7 @@ public class ExportExcelServiceImpl implements IExportExcelService {
|
||||
return everyRowData;
|
||||
});
|
||||
|
||||
ExcelUtil.exportExcel(outList, "下拉框示例", ExportDemoVo.class, response, options);
|
||||
ExcelUtil.exportExcel(outList, null, "下拉框示例", ExportDemoVo.class, response, options);
|
||||
}
|
||||
|
||||
private String buildOptions(List<DemoCityData> cityDataList, Integer id) {
|
||||
|
@ -50,7 +50,7 @@ public class SysLogininforController extends BaseController {
|
||||
@PostMapping("/export")
|
||||
public void export(SysLogininforBo logininfor, HttpServletResponse response) {
|
||||
List<SysLogininforVo> list = logininforService.selectLogininforList(logininfor);
|
||||
ExcelUtil.exportExcel(list, "登录日志", SysLogininforVo.class, response);
|
||||
ExcelUtil.exportExcel(list, null, "登录日志", SysLogininforVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,7 +48,7 @@ public class SysOperlogController extends BaseController {
|
||||
@PostMapping("/export")
|
||||
public void export(SysOperLogBo operLog, HttpServletResponse response) {
|
||||
List<SysOperLogVo> list = operLogService.selectOperLogList(operLog);
|
||||
ExcelUtil.exportExcel(list, "操作日志", SysOperLogVo.class, response);
|
||||
ExcelUtil.exportExcel(list, null, "操作日志", SysOperLogVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,7 +53,7 @@ public class SysClientController extends BaseController {
|
||||
@PostMapping("/export")
|
||||
public void export(SysClientBo bo, HttpServletResponse response) {
|
||||
List<SysClientVo> list = sysClientService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "客户端管理", SysClientVo.class, response);
|
||||
ExcelUtil.exportExcel(list, null, "客户端管理", SysClientVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,7 +48,7 @@ public class SysConfigController extends BaseController {
|
||||
@PostMapping("/export")
|
||||
public void export(SysConfigBo config, HttpServletResponse response) {
|
||||
List<SysConfigVo> list = configService.selectConfigList(config);
|
||||
ExcelUtil.exportExcel(list, "参数数据", SysConfigVo.class, response);
|
||||
ExcelUtil.exportExcel(list, null, "参数数据", SysConfigVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,7 +52,7 @@ public class SysDictDataController extends BaseController {
|
||||
@PostMapping("/export")
|
||||
public void export(SysDictDataBo dictData, HttpServletResponse response) {
|
||||
List<SysDictDataVo> list = dictDataService.selectDictDataList(dictData);
|
||||
ExcelUtil.exportExcel(list, "字典数据", SysDictDataVo.class, response);
|
||||
ExcelUtil.exportExcel(list, null, "字典数据", SysDictDataVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,7 +48,7 @@ public class SysDictTypeController extends BaseController {
|
||||
@PostMapping("/export")
|
||||
public void export(SysDictTypeBo dictType, HttpServletResponse response) {
|
||||
List<SysDictTypeVo> list = dictTypeService.selectDictTypeList(dictType);
|
||||
ExcelUtil.exportExcel(list, "字典类型", SysDictTypeVo.class, response);
|
||||
ExcelUtil.exportExcel(list, null, "字典类型", SysDictTypeVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,7 +51,7 @@ public class SysPostController extends BaseController {
|
||||
@PostMapping("/export")
|
||||
public void export(SysPostBo post, HttpServletResponse response) {
|
||||
List<SysPostVo> list = postService.selectPostList(post);
|
||||
ExcelUtil.exportExcel(list, "岗位数据", SysPostVo.class, response);
|
||||
ExcelUtil.exportExcel(list, null, "岗位数据", SysPostVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,7 +57,7 @@ public class SysRoleController extends BaseController {
|
||||
@PostMapping("/export")
|
||||
public void export(SysRoleBo role, HttpServletResponse response) {
|
||||
List<SysRoleVo> list = roleService.selectRoleList(role);
|
||||
ExcelUtil.exportExcel(list, "角色数据", SysRoleVo.class, response);
|
||||
ExcelUtil.exportExcel(list, null, "角色数据", SysRoleVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,7 +63,7 @@ public class SysTenantController extends BaseController {
|
||||
@PostMapping("/export")
|
||||
public void export(SysTenantBo bo, HttpServletResponse response) {
|
||||
List<SysTenantVo> list = tenantService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "租户", SysTenantVo.class, response);
|
||||
ExcelUtil.exportExcel(list, null, "租户", SysTenantVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,7 +69,7 @@ public class SysTenantPackageController extends BaseController {
|
||||
@PostMapping("/export")
|
||||
public void export(SysTenantPackageBo bo, HttpServletResponse response) {
|
||||
List<SysTenantPackageVo> list = tenantPackageService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "租户套餐", SysTenantPackageVo.class, response);
|
||||
ExcelUtil.exportExcel(list, null, "租户套餐", SysTenantPackageVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,7 +72,7 @@ public class SysUserController extends BaseController {
|
||||
@PostMapping("/export")
|
||||
public void export(SysUserBo user, HttpServletResponse response) {
|
||||
List<SysUserExportVo> list = userService.selectUserExportList(user);
|
||||
ExcelUtil.exportExcel(list, "用户数据", SysUserExportVo.class, response);
|
||||
ExcelUtil.exportExcel(list, null, "用户数据", SysUserExportVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -94,7 +94,7 @@ public class SysUserController extends BaseController {
|
||||
*/
|
||||
@PostMapping("/importTemplate")
|
||||
public void importTemplate(HttpServletResponse response) {
|
||||
ExcelUtil.exportExcel(new ArrayList<>(), "用户数据", SysUserImportVo.class, response);
|
||||
ExcelUtil.exportExcel(new ArrayList<>(), null, "用户数据", SysUserImportVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,7 +54,7 @@ public class TestLeaveController extends BaseController {
|
||||
@PostMapping("/export")
|
||||
public void export(TestLeaveBo bo, HttpServletResponse response) {
|
||||
List<TestLeaveVo> list = testLeaveService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "请假", TestLeaveVo.class, response);
|
||||
ExcelUtil.exportExcel(list, null, "请假", TestLeaveVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -54,7 +54,7 @@ public class WfCategoryController extends BaseController {
|
||||
@PostMapping("/export")
|
||||
public void export(WfCategoryBo bo, HttpServletResponse response) {
|
||||
List<WfCategoryVo> list = wfCategoryService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "流程分类", WfCategoryVo.class, response);
|
||||
ExcelUtil.exportExcel(list, null, "流程分类", WfCategoryVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,7 +62,7 @@ public class WfFormManageController extends BaseController {
|
||||
@PostMapping("/export")
|
||||
public void export(WfFormManageBo bo, HttpServletResponse response) {
|
||||
List<WfFormManageVo> list = wfFormManageService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "表单管理", WfFormManageVo.class, response);
|
||||
ExcelUtil.exportExcel(list, null, "表单管理", WfFormManageVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user