|
|
@@ -5,17 +5,13 @@ import com.alibaba.excel.ExcelWriter;
|
|
|
import com.alibaba.excel.annotation.ExcelProperty;
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.sckw.core.common.enums.NumberConstant;
|
|
|
import com.sckw.core.model.constant.Global;
|
|
|
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 +26,6 @@ import java.time.LocalDateTime;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.Properties;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -43,14 +38,24 @@ import java.util.Properties;
|
|
|
*/
|
|
|
@Slf4j
|
|
|
public class ExcelUtil {
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 数据导出
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ * @param clazz
|
|
|
+ * @param data
|
|
|
+ * @param <T>
|
|
|
+ */
|
|
|
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);
|
|
|
+ EasyExcel.write(response.getOutputStream(), clazz)
|
|
|
+ .autoCloseStream(Boolean.FALSE)
|
|
|
+ .registerConverter(new LongStringConverter())
|
|
|
+ .sheet(excelContext.sheetName()).doWrite(data);
|
|
|
} catch (Exception e) {
|
|
|
buildResponse(response, e);
|
|
|
}
|