com.xinjump.easyexcel.helper.EasyExcelHelper2 Maven / Gradle / Ivy
The newest version!
//package com.xinjump.easyexcel.helper;
//
//import com.alibaba.excel.EasyExcelFactory;
//import com.alibaba.excel.ExcelWriter;
//import com.alibaba.excel.annotation.ExcelProperty;
//import com.alibaba.excel.support.ExcelTypeEnum;
//import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
//import com.alibaba.excel.write.handler.WriteHandler;
//import com.alibaba.excel.write.metadata.WriteSheet;
//import com.xinjump.base.util.collect.CollectionUtils;
//import com.xinjump.base.util.collect.ListUtils;
//import com.xinjump.base.util.lang.StringUtils;
//import com.xinjump.easyexcel.ExcelRow;
//import com.xinjump.easyexcel.annotation.Excel;
//import com.xinjump.easyexcel.event.AnalysisEventAutoListener;
//import com.xinjump.easyexcel.event.ExcelManager;
//import com.xinjump.easyexcel.exceptions.ExcelException;
//import com.xinjump.easyexcel.util.ExcelUtil;
//import com.xinjump.easyexcel.write.model.WriteSheetModel;
//import com.xinjump.easyexcel.write.selected.SelectedSheetWriteHandler;
//import com.xinjump.easyexcel.write.style.CustomColumnWidthStyleHandler;
//import lombok.extern.slf4j.Slf4j;
//
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.OutputStream;
//import java.net.URLEncoder;
//import java.util.Arrays;
//import java.util.Comparator;
//import java.util.List;
//import java.util.function.BiFunction;
//import java.util.stream.Collectors;
//
///**
// * @author xinjump
// * @version 1.1
// * @date 2020/9/20 17:04
// * @see com.xinjump.easyexcel.helper
// */
//@SuppressWarnings({"rawtypes"})
//@Slf4j
//public final class EasyExcelHelper2 extends EasyExcelFactory {
//
// public static T read(String type, InputStream is) {
// return read(type, is, 0);
// }
//
// public static T read(String type, InputStream is, Integer sheetNo) {
// return read(type, is, sheetNo, null);
// }
//
// /**
// * @param type 指定导入执行的EventListener
// * @param is 文件流
// * @param sheetNo 指定读取sheet
// * @param response 如果有错误直接下载错误模板
// */
// public static T read(String type, InputStream is, Integer sheetNo, HttpServletResponse response) {
// return read(is, sheetNo, ExcelManager.getEventListener(type, response));
// }
//
// public static T read(InputStream is, T listener) {
// return read(is, 0, listener);
// }
//
// public static T read(InputStream is, Integer sheetNo, T listener) {
// read(is, listener.getClazz(), listener).sheet(sheetNo).doRead();
// return listener;
// }
//
// public static void downloadTemplate(HttpServletResponse response, Class clazz, List data) {
// Excel excel = ExcelUtil.getExcel(clazz);
// List> heads = Arrays.stream(clazz.getDeclaredFields())
// .map(e -> e.getAnnotation(ExcelProperty.class))
// .sorted(Comparator.comparingInt(ExcelProperty::index))
// .map(excelProperty -> ListUtils.newArrayList(excelProperty.value()))
// .collect(Collectors.toList());
// writeExcel(response, clazz, heads, 0, excel.sheetName(), excel.fileName(), data, new CustomColumnWidthStyleHandler(), new SelectedSheetWriteHandler(clazz));
// }
//
// public static WriteSheet downloadTemplates(Class clazz, Integer sheetNo, String sheetName) {
// Excel excel = ExcelUtil.getExcel(clazz);
// List> heads = Arrays.stream(clazz.getDeclaredFields())
// .map(e -> e.getAnnotation(ExcelProperty.class))
// .sorted(Comparator.comparingInt(ExcelProperty::index))
// .map(excelProperty -> ListUtils.newArrayList(excelProperty.value()))
// .collect(Collectors.toList());
// return writeSheet(heads, sheetNo, sheetName);
// }
//
// public static void downloadSingleError(HttpServletResponse response, Class clazz, List example) {
// Excel excel = ExcelUtil.getExcel(clazz);
// Excel superExcel = ExcelUtil.getSuperExcel(clazz);
// String sheetName = StringUtils.isBlank(excel.sheetName()) ? excel.fileName() : excel.sheetName() + superExcel.sheetName();
// String fileName = excel.fileName() + superExcel.fileName();
// writeExcel(response, clazz, null, 0, sheetName, fileName, example, new CustomColumnWidthStyleHandler(), new SelectedSheetWriteHandler(clazz));
// }
//
// public static void writeExcel(HttpServletResponse response, List> heads, Integer sheetNo, String sheetName, String fileName, List data) {
// writeExcel(response, null, heads, sheetNo, sheetName, fileName, data, new CustomColumnWidthStyleHandler());
// }
//
// public static void writeExcel(HttpServletResponse response, Class clazz, List data) {
// writeExcel(response, clazz, data, new CustomColumnWidthStyleHandler(), new SelectedSheetWriteHandler(clazz));
// }
//
// /**
// * 导出Excel到web
// *
// * @param response 响应
// * @param data 要导出的数据
// * @param writeHandlers writeHandlers
// */
// public static void writeExcel(HttpServletResponse response, Class clazz, List data, WriteHandler... writeHandlers) {
// Excel excel = ExcelUtil.getExcel(clazz);
// writeExcel(response, clazz, null, 0, excel.sheetName(), excel.fileName(), data, writeHandlers);
// }
//
// public static void writeExcel(HttpServletResponse response, List> heads, Integer sheetNo, String sheetName,
// String fileName, List data, WriteHandler... writeHandlers) {
// WriteSheet writeSheet = writeSheet(null, heads, sheetNo, sheetName, writeHandlers);
// ExcelWriter excelWriter = excelWriter(response, fileName);
// excelWriter.write(CollectionUtils.isEmpty(data) ? ListUtils.newArrayList() : data, writeSheet);
// excelWriter.finish();
// }
//
// public static void writeExcel(HttpServletResponse response, Class clazz, List> heads, Integer sheetNo,
// String sheetName, String fileName, List data, WriteHandler... writeHandlers) {
// WriteSheet writeSheet = writeSheet(clazz, heads, sheetNo, sheetName, writeHandlers);
// ExcelWriter excelWriter = excelWriter(response, fileName);
// excelWriter.write(CollectionUtils.isEmpty(data) ? ListUtils.newArrayList() : data, writeSheet);
// excelWriter.finish();
// }
//
// public static void writeExcel(HttpServletResponse response, String fileName, List data, WriteSheet writeSheet) {
// ExcelWriter excelWriter = excelWriter(response, fileName);
// excelWriter.write(data, writeSheet);
// excelWriter.finish();
// }
//
// public static void writeExcel(HttpServletResponse response, String fileName, List writeSheetModels) {
// ExcelWriter excelWriter = excelWriter(response, fileName);
// for (WriteSheetModel writeSheetModel : writeSheetModels) {
// excelWriter.write(writeSheetModel.getData(), writeSheetModel.getWriteSheet());
// }
// excelWriter.finish();
// }
//
// /**
// * 创建即将导出的sheet页(sheet页中含有带下拉框的列)
// *
// * @param clazz 导出的表头信息和配置
// * @param sheetNo sheet索引
// * @param sheetName sheet名称
// * @param 泛型
// * @return sheet页
// */
// public static WriteSheet writeSheet(Class clazz, Integer sheetNo, String sheetName) {
// return writeSheet(clazz, null, sheetNo, sheetName, new CustomColumnWidthStyleHandler(), new SelectedSheetWriteHandler(clazz));
// }
//
// public static ExcelWriterSheetBuilder writeSheetBuilder(Class clazz, Integer sheetNo, String sheetName) {
// return writeSheetBuilder(clazz, null, sheetNo, sheetName, new CustomColumnWidthStyleHandler(), new SelectedSheetWriteHandler(clazz));
// }
//
// public static WriteSheet writeSheet(List> heads, Integer sheetNo, String sheetName) {
// return writeSheet(null, heads, sheetNo, sheetName, new CustomColumnWidthStyleHandler());
// }
//
// public static ExcelWriterSheetBuilder writeSheetBuilder(List> heads, Integer sheetNo, String sheetName) {
// return writeSheetBuilder(null, heads, sheetNo, sheetName, new CustomColumnWidthStyleHandler());
// }
//
// public static WriteSheet writeSheet(Class clazz, List> heads, Integer sheetNo, String sheetName,
// WriteHandler... writeHandlers) {
// return writeSheetBuilder(clazz, heads, sheetNo, sheetName, writeHandlers).build();
// }
//
// public static ExcelWriterSheetBuilder writeSheetBuilder(Class clazz, Integer sheetNo, String sheetName,
// WriteHandler... writeHandlers) {
// return writeSheetBuilder(clazz, null, sheetNo, sheetName, writeHandlers);
// }
//
// public static ExcelWriterSheetBuilder writeSheetBuilder(List> heads, Integer sheetNo, String sheetName,
// WriteHandler... writeHandlers) {
// return writeSheetBuilder(null, heads, sheetNo, sheetName, writeHandlers);
// }
//
// public static ExcelWriterSheetBuilder writeSheetBuilder(Class clazz, List> heads, Integer sheetNo,
// String sheetName, WriteHandler... writeHandlers) {
// ExcelWriterSheetBuilder excelWriterSheetBuilder = writerSheet(sheetNo, sheetName);
// if (CollectionUtils.isEmpty(heads)) {
// excelWriterSheetBuilder.head(clazz);
// } else {
// excelWriterSheetBuilder.head(heads);
// }
// for (WriteHandler writeHandler : writeHandlers) {
// excelWriterSheetBuilder.registerWriteHandler(writeHandler);
// }
// return excelWriterSheetBuilder;
// }
//
// public static ExcelWriter excelWriter(HttpServletResponse response, String fileName) {
//
// return write(OutputStream.apply(response, fileName)).build();
// }
//
// public static BiFunction OutputStream = (response, fileName) -> {
// try {
// String finalFileName = URLEncoder.encode((fileName + ExcelTypeEnum.XLSX.getValue()), "UTF-8");
// response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
// response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
// response.setHeader("Pragma", "no-cache");
// response.setHeader("Expires", "0");
// response.setHeader("Content-Disposition", "attachment;filename=" + finalFileName);
// response.setCharacterEncoding("UTF-8");
// response.setContentType("application/vnd.ms-excel;charset=UTF-8");
// return response.getOutputStream();
// } catch (IOException e) {
// throw new ExcelException("获取文件失败");
// }
// };
//
//}