统计数据导出
This commit is contained in:
@@ -8,6 +8,7 @@ import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.write.builder.ExcelWriterBuilder;
|
||||
import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
|
||||
import com.alibaba.excel.write.handler.SheetWriteHandler;
|
||||
import com.alibaba.excel.write.merge.OnceAbsoluteMergeStrategy;
|
||||
import com.alibaba.excel.write.metadata.WriteSheet;
|
||||
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
||||
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
|
||||
@@ -26,6 +27,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* EasyExcel导出工具类
|
||||
*
|
||||
* @author yjjie
|
||||
* @date 2026/1/28 10:48
|
||||
*/
|
||||
@@ -34,14 +36,18 @@ public class ExcelExportUtil {
|
||||
|
||||
private static final ExcelExportConfig DEFAULT_CONFIG = new ExcelExportConfig();
|
||||
|
||||
public static OnceAbsoluteMergeStrategy createMergeStrategy(int firstRow, int lastRow, int firstCol, int lastCol) {
|
||||
return new OnceAbsoluteMergeStrategy(firstRow, lastRow, firstCol, lastCol);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出Excel到HttpServletResponse
|
||||
*
|
||||
* @param data 数据列表
|
||||
* @param clazz 数据类型
|
||||
* @param data 数据列表
|
||||
* @param clazz 数据类型
|
||||
* @param fileName 文件名(不含扩展名)
|
||||
* @param response HttpServletResponse
|
||||
* @param <T> 数据类型
|
||||
* @param <T> 数据类型
|
||||
*/
|
||||
public static <T> void exportToResponse(List<T> data, Class<T> clazz,
|
||||
String fileName, HttpServletResponse response) {
|
||||
@@ -51,12 +57,12 @@ public class ExcelExportUtil {
|
||||
/**
|
||||
* 导出Excel到HttpServletResponse(自定义配置)
|
||||
*
|
||||
* @param data 数据列表
|
||||
* @param clazz 数据类型
|
||||
* @param data 数据列表
|
||||
* @param clazz 数据类型
|
||||
* @param fileName 文件名(不含扩展名)
|
||||
* @param config 配置信息
|
||||
* @param config 配置信息
|
||||
* @param response HttpServletResponse
|
||||
* @param <T> 数据类型
|
||||
* @param <T> 数据类型
|
||||
*/
|
||||
public static <T> void exportToResponse(List<T> data, Class<T> clazz,
|
||||
String fileName, ExcelExportConfig config,
|
||||
@@ -86,10 +92,10 @@ public class ExcelExportUtil {
|
||||
/**
|
||||
* 导出Excel到文件
|
||||
*
|
||||
* @param data 数据列表
|
||||
* @param clazz 数据类型
|
||||
* @param data 数据列表
|
||||
* @param clazz 数据类型
|
||||
* @param filePath 文件路径
|
||||
* @param <T> 数据类型
|
||||
* @param <T> 数据类型
|
||||
*/
|
||||
public static <T> void exportToFile(List<T> data, Class<T> clazz, String filePath) {
|
||||
exportToFile(data, clazz, filePath, DEFAULT_CONFIG);
|
||||
@@ -98,11 +104,11 @@ public class ExcelExportUtil {
|
||||
/**
|
||||
* 导出Excel到文件(自定义配置)
|
||||
*
|
||||
* @param data 数据列表
|
||||
* @param clazz 数据类型
|
||||
* @param data 数据列表
|
||||
* @param clazz 数据类型
|
||||
* @param filePath 文件路径
|
||||
* @param config 配置信息
|
||||
* @param <T> 数据类型
|
||||
* @param config 配置信息
|
||||
* @param <T> 数据类型
|
||||
*/
|
||||
public static <T> void exportToFile(List<T> data, Class<T> clazz,
|
||||
String filePath, ExcelExportConfig config) {
|
||||
@@ -124,11 +130,11 @@ public class ExcelExportUtil {
|
||||
/**
|
||||
* 带样式的Excel导出到Response
|
||||
*
|
||||
* @param data 数据列表
|
||||
* @param clazz 数据类型
|
||||
* @param data 数据列表
|
||||
* @param clazz 数据类型
|
||||
* @param fileName 文件名
|
||||
* @param response HttpServletResponse
|
||||
* @param <T> 数据类型
|
||||
* @param <T> 数据类型
|
||||
*/
|
||||
public static <T> void exportWithStyleToResponse(List<T> data, Class<T> clazz,
|
||||
String fileName, HttpServletResponse response) {
|
||||
@@ -162,11 +168,11 @@ public class ExcelExportUtil {
|
||||
* 大数据量分批导出(避免内存溢出)
|
||||
*
|
||||
* @param dataSupplier 数据提供者(分页获取数据)
|
||||
* @param clazz 数据类型
|
||||
* @param fileName 文件名
|
||||
* @param response HttpServletResponse
|
||||
* @param batchSize 每批大小
|
||||
* @param <T> 数据类型
|
||||
* @param clazz 数据类型
|
||||
* @param fileName 文件名
|
||||
* @param response HttpServletResponse
|
||||
* @param batchSize 每批大小
|
||||
* @param <T> 数据类型
|
||||
*/
|
||||
public static <T> void exportBigDataToResponse(DataSupplier<T> dataSupplier,
|
||||
Class<T> clazz, String fileName,
|
||||
@@ -254,13 +260,13 @@ public class ExcelExportUtil {
|
||||
* 带合并单元格的导出到Response
|
||||
* 多sheet导出到response
|
||||
*
|
||||
* @param sheetDataList 数据列表
|
||||
* @param fileName 文件名
|
||||
* @param response HttpServletResponse
|
||||
* @param sheetDataList 数据列表
|
||||
* @param fileName 文件名
|
||||
* @param response HttpServletResponse
|
||||
*/
|
||||
public static void exportMultipleSheetsToResponse(List<SheetData> sheetDataList,
|
||||
String fileName,
|
||||
HttpServletResponse response) {
|
||||
String fileName,
|
||||
HttpServletResponse response) {
|
||||
if (CollectionUtil.isEmpty(sheetDataList)) {
|
||||
throw new CzgException("数据列表不能为空");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user