|
|
@@ -10,10 +10,7 @@ import com.sckw.core.common.enums.NumberConstant;
|
|
|
import com.sckw.core.web.response.HttpResult;
|
|
|
import com.sckw.excel.annotation.ExcelContext;
|
|
|
import com.sckw.excel.annotation.ExcelSelected;
|
|
|
-import com.sckw.excel.config.easyexcel.ExcelSelectedResolve;
|
|
|
-import com.sckw.excel.config.easyexcel.LocalDateTimeConverter;
|
|
|
-import com.sckw.excel.config.easyexcel.RowWriteHandlerImpl;
|
|
|
-import com.sckw.excel.config.easyexcel.SelectedSheetWriteHandler;
|
|
|
+import com.sckw.excel.config.easyexcel.*;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.util.Assert;
|
|
|
@@ -30,7 +27,6 @@ import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 封装easyexcel
|
|
|
*
|
|
|
@@ -42,6 +38,18 @@ import java.util.Map;
|
|
|
@Slf4j
|
|
|
public class ExcelUtil {
|
|
|
|
|
|
+ public static <T> void downData(HttpServletResponse response, Class<T> clazz, List<T> data) {
|
|
|
+ Assert.notNull(clazz, "clazz can't be null");
|
|
|
+ Assert.isTrue(data != null && !data.isEmpty(), "data can't be empty");
|
|
|
+ try {
|
|
|
+ ExcelContext excelContext = clazz.getAnnotation(ExcelContext.class);
|
|
|
+ buildResponse(response, excelContext.fileName());
|
|
|
+ EasyExcel.write(response.getOutputStream(), clazz).autoCloseStream(Boolean.FALSE).sheet(excelContext.sheetName()).doWrite(data);
|
|
|
+ } catch (Exception e) {
|
|
|
+ buildResponse(response, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static <T> void download(HttpServletResponse response, Class<T> clazz, List<T> data) {
|
|
|
// StaticComponentContainer.Modules.exportAllToAll();
|
|
|
Assert.notNull(clazz, "clazz can't be null");
|