| | |
| | | import com.alibaba.excel.write.metadata.fill.FillConfig; |
| | | import com.alibaba.excel.write.metadata.fill.FillWrapper; |
| | | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
| | | import org.dromara.common.core.utils.StringUtils; |
| | | import org.dromara.common.core.utils.file.FileUtils; |
| | | import org.dromara.common.excel.convert.ExcelBigNumberConvert; |
| | | import org.dromara.common.excel.core.CellMergeStrategy; |
| | | import org.dromara.common.excel.core.DefaultExcelListener; |
| | | import org.dromara.common.excel.core.ExcelListener; |
| | | import org.dromara.common.excel.core.ExcelResult; |
| | | import jakarta.servlet.ServletOutputStream; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.AccessLevel; |
| | | import lombok.NoArgsConstructor; |
| | | import org.dromara.common.core.utils.StringUtils; |
| | | import org.dromara.common.core.utils.file.FileUtils; |
| | | import org.dromara.common.excel.convert.ExcelBigNumberConvert; |
| | | import org.dromara.common.excel.core.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | try { |
| | | resetResponse(sheetName, response); |
| | | ServletOutputStream os = response.getOutputStream(); |
| | | exportExcel(list, sheetName, clazz, false, os); |
| | | exportExcel(list, sheetName, clazz, false, os, null); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException("导出Excel异常"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 导出excel |
| | | * |
| | | * @param list 导出数据集合 |
| | | * @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) { |
| | | try { |
| | | resetResponse(sheetName, response); |
| | | ServletOutputStream os = response.getOutputStream(); |
| | | exportExcel(list, sheetName, clazz, false, os, options); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException("导出Excel异常"); |
| | | } |
| | |
| | | try { |
| | | resetResponse(sheetName, response); |
| | | ServletOutputStream os = response.getOutputStream(); |
| | | exportExcel(list, sheetName, clazz, merge, os); |
| | | exportExcel(list, sheetName, clazz, merge, os, null); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException("导出Excel异常"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 导出excel |
| | | * |
| | | * @param list 导出数据集合 |
| | | * @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) { |
| | | try { |
| | | resetResponse(sheetName, response); |
| | | ServletOutputStream os = response.getOutputStream(); |
| | | exportExcel(list, sheetName, clazz, merge, os, options); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException("导出Excel异常"); |
| | | } |
| | |
| | | * @param os 输出流 |
| | | */ |
| | | public static <T> void exportExcel(List<T> list, String sheetName, Class<T> clazz, OutputStream os) { |
| | | exportExcel(list, sheetName, clazz, false, os); |
| | | exportExcel(list, sheetName, clazz, false, os, null); |
| | | } |
| | | |
| | | /** |
| | | * 导出excel |
| | | * |
| | | * @param list 导出数据集合 |
| | | * @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); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param merge 是否合并单元格 |
| | | * @param os 输出流 |
| | | */ |
| | | public static <T> void exportExcel(List<T> list, String sheetName, Class<T> clazz, boolean merge, OutputStream os) { |
| | | public static <T> void exportExcel(List<T> list, String sheetName, Class<T> clazz, boolean merge, |
| | | OutputStream os, List<DropDownOptions> options) { |
| | | ExcelWriterSheetBuilder builder = EasyExcel.write(os, clazz) |
| | | .autoCloseStream(false) |
| | | // 自动适配 |
| | |
| | | if (merge) { |
| | | // 合并处理器 |
| | | builder.registerWriteHandler(new CellMergeStrategy(list, true)); |
| | | } |
| | | if (CollUtil.isNotEmpty(options)) { |
| | | // 添加下拉框操作 |
| | | builder.registerWriteHandler(new ExcelDownHandler(options)); |
| | | } |
| | | builder.doWrite(list); |
| | | } |
| | |
| | | /** |
| | | * 重置响应体 |
| | | */ |
| | | private static void resetResponse(String sheetName, HttpServletResponse response) { |
| | | private static void resetResponse(String sheetName, HttpServletResponse response) throws UnsupportedEncodingException { |
| | | String filename = encodingFilename(sheetName); |
| | | FileUtils.setAttachmentResponseHeader(response, filename); |
| | | response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=UTF-8"); |
| | |
| | | if (StringUtils.containsAny(propertyValue, separator)) { |
| | | for (String value : propertyValue.split(separator)) { |
| | | if (itemArray[0].equals(value)) { |
| | | propertyString.append(itemArray[1]).append(separator); |
| | | propertyString.append(itemArray[1] + separator); |
| | | break; |
| | | } |
| | | } |
| | |
| | | if (StringUtils.containsAny(propertyValue, separator)) { |
| | | for (String value : propertyValue.split(separator)) { |
| | | if (itemArray[1].equals(value)) { |
| | | propertyString.append(itemArray[0]).append(separator); |
| | | propertyString.append(itemArray[0] + separator); |
| | | break; |
| | | } |
| | | } |