类 ExcelHelper
java.lang.Object
com.diboot.file.util.ExcelHelper
excel数据导入导出工具类
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明构建 Excel 表头映射static <T> voidbuildWriteSheet(String sheetName, Class<T> clazz, Collection<String> columnNameList, java.util.function.BiConsumer<CommentWriteHandler, com.alibaba.excel.write.metadata.WriteSheet> consumer, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) 构建WriteSheetstatic <T> voidexportExcel(jakarta.servlet.http.HttpServletResponse response, String fileName, Class<T> clazz, Collection<String> columnNameList, java.util.function.Supplier<List<T>> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) web 导出excelstatic <T> voidexportExcel(jakarta.servlet.http.HttpServletResponse response, String fileName, Class<T> clazz, Collection<String> columnNameList, List<T> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) web 导出excelstatic <T> voidexportExcel(jakarta.servlet.http.HttpServletResponse response, String fileName, Class<T> clazz, List<T> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) web 导出excelstatic voidexportExcel(jakarta.servlet.http.HttpServletResponse response, String fileName, java.util.function.Consumer<com.alibaba.excel.ExcelWriter> writerConsumer) web 导出excel 自定义Sheet写入getTableHeads(Class<?> clazz) 获取 Excel 模板中的表头static voidread(InputStream inputStream, com.alibaba.excel.read.listener.ReadListener<?> listener) 读取ecxelstatic <T> voidread(InputStream inputStream, com.alibaba.excel.read.listener.ReadListener<T> listener, Class<T> headClazz) 读取ecxelstatic <T> voidread(InputStream inputStream, com.alibaba.excel.support.ExcelTypeEnum excelType, com.alibaba.excel.read.listener.ReadListener<T> listener, Class<T> headClazz) 读取ecxelstatic voidsetExportExcelResponseHeader(jakarta.servlet.http.HttpServletResponse response, String fileName) 设置导出的excel 响应头static <T> voidwrite(OutputStream outputStream, Class<T> clazz, Collection<String> columnNameList, Boolean autoClose, java.util.function.Supplier<List<T>> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) 多次写入static <T> voidwrite(OutputStream outputStream, Class<T> clazz, Collection<String> columnNameList, java.util.function.Supplier<List<T>> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) 分批多次写入static <T> voidwrite(OutputStream outputStream, Class<T> clazz, Collection<String> columnNameList, List<T> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) Excel写入static <T> voidwrite(OutputStream outputStream, Class<T> clazz, List<T> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) Excel写入static voidwrite(OutputStream outputStream, String sheetName, List<List<String>> headList, List<List<String>> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) 简单将数据写入excel文件static <T> voidwriteSheet(com.alibaba.excel.ExcelWriter excel, String sheetName, Class<T> clazz, Collection<String> columnNameList, java.util.function.Supplier<List<T>> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) Sheet 写入static <T> voidwriteSheet(com.alibaba.excel.ExcelWriter excel, String sheetName, Class<T> clazz, java.util.function.Supplier<List<T>> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) Sheet 写入static <T> voidwriteSheet(com.alibaba.excel.ExcelWriter excel, String sheetName, Class<T> clazz, List<T> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) Sheet 写入
-
构造器详细资料
-
ExcelHelper
public ExcelHelper()
-
-
方法详细资料
-
read
public static void read(InputStream inputStream, com.alibaba.excel.read.listener.ReadListener<?> listener) 读取ecxel- 参数:
inputStream-listener-
-
read
public static <T> void read(InputStream inputStream, com.alibaba.excel.read.listener.ReadListener<T> listener, Class<T> headClazz) 读取ecxel- 参数:
inputStream-listener-headClazz- ExcelModel.class
-
read
public static <T> void read(InputStream inputStream, com.alibaba.excel.support.ExcelTypeEnum excelType, com.alibaba.excel.read.listener.ReadListener<T> listener, Class<T> headClazz) 读取ecxel- 参数:
inputStream-excelType- excel类型,为空自动推断listener-headClazz- ExcelModel.class
-
write
public static void write(OutputStream outputStream, String sheetName, List<List<String>> headList, List<List<String>> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) 简单将数据写入excel文件默认列宽自适应数据长度, 可自定义
- 参数:
outputStream-sheetName-dataList-writeHandlers-
-
write
public static <T> void write(OutputStream outputStream, Class<T> clazz, List<T> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) Excel写入默认支持:批注写入、单元格下拉选项写入
- 参数:
outputStream-clazz- 导出的ExcelModeldataList-writeHandlers- 写入处理程序
-
write
public static <T> void write(OutputStream outputStream, Class<T> clazz, Collection<String> columnNameList, List<T> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) Excel写入- 参数:
outputStream-clazz- 导出的ExcelModelcolumnNameList- 需要导出的列属性名,为空时导出所有列dataList-writeHandlers- 写入处理程序
-
write
public static <T> void write(OutputStream outputStream, Class<T> clazz, Collection<String> columnNameList, java.util.function.Supplier<List<T>> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) 分批多次写入- 参数:
outputStream-clazz-columnNameList-dataList-writeHandlers-
-
write
public static <T> void write(OutputStream outputStream, Class<T> clazz, Collection<String> columnNameList, Boolean autoClose, java.util.function.Supplier<List<T>> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) 多次写入- 参数:
outputStream-clazz-columnNameList-autoClose- 是否自动关闭流dataList-writeHandlers-
-
writeSheet
public static <T> void writeSheet(com.alibaba.excel.ExcelWriter excel, String sheetName, Class<T> clazz, List<T> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) Sheet 写入- 类型参数:
T- 导出的ExcelModel泛型- 参数:
excel- Excel 编写器sheetName- Sheet名称clazz- 导出的ExcelModeldataList- 数据列表writeHandlers- 写入处理程序
-
writeSheet
public static <T> void writeSheet(com.alibaba.excel.ExcelWriter excel, String sheetName, Class<T> clazz, java.util.function.Supplier<List<T>> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) Sheet 写入- 类型参数:
T- 导出的ExcelModel泛型- 参数:
excel- Excel 编写器sheetName- Sheet名称clazz- 导出的ExcelModeldataList- 数据列表提供者writeHandlers- 写入处理程序
-
writeSheet
public static <T> void writeSheet(com.alibaba.excel.ExcelWriter excel, String sheetName, Class<T> clazz, Collection<String> columnNameList, java.util.function.Supplier<List<T>> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) Sheet 写入- 类型参数:
T- 导出的ExcelModel泛型- 参数:
excel- Excel 编写器sheetName- Sheet名称clazz- 导出的ExcelModelcolumnNameList- 需要导出的列属性名,为空时导出所有列dataList- 数据列表提供者writeHandlers- 写入处理程序
-
buildWriteSheet
public static <T> void buildWriteSheet(String sheetName, Class<T> clazz, Collection<String> columnNameList, java.util.function.BiConsumer<CommentWriteHandler, com.alibaba.excel.write.metadata.WriteSheet> consumer, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) 构建WriteSheet默认:自列适应宽、单元格下拉选项(验证)写入,批注写入
- 参数:
sheetName- 可指定sheetNamecolumnNameList- 需要导出的ExcelModel列字段名称列表,为空时导出所有列clazz- 导出的ExcelModelconsumer- 分批写入writeHandlers- 写入处理程序
-
exportExcel
public static <T> void exportExcel(jakarta.servlet.http.HttpServletResponse response, String fileName, Class<T> clazz, List<T> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) web 导出excel默认:自列适应宽、单元格下拉选项(验证)写入,批注写入
- 参数:
response-fileName-clazz- 导出的ExcelModeldataList-writeHandlers- 写入处理程序
-
exportExcel
public static <T> void exportExcel(jakarta.servlet.http.HttpServletResponse response, String fileName, Class<T> clazz, Collection<String> columnNameList, List<T> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) web 导出excel默认 自列适应宽、单元格下拉选项(验证)写入,批注写入
- 参数:
response-clazz- 导出的ExcelModeldataList- 导出的数据columnNameList- 需要导出的ExcelModel列字段名称列表,为空时导出所有列writeHandlers- 写入处理程序
-
exportExcel
public static <T> void exportExcel(jakarta.servlet.http.HttpServletResponse response, String fileName, Class<T> clazz, Collection<String> columnNameList, java.util.function.Supplier<List<T>> dataList, com.alibaba.excel.write.handler.WriteHandler... writeHandlers) web 导出excel分批多次写入
- 类型参数:
T-- 参数:
response-fileName-clazz-columnNameList-dataList-writeHandlers-
-
exportExcel
public static void exportExcel(jakarta.servlet.http.HttpServletResponse response, String fileName, java.util.function.Consumer<com.alibaba.excel.ExcelWriter> writerConsumer) web 导出excel 自定义Sheet写入- 参数:
response-fileName-writerConsumer-
-
setExportExcelResponseHeader
public static void setExportExcelResponseHeader(jakarta.servlet.http.HttpServletResponse response, String fileName) 设置导出的excel 响应头- 参数:
response-fileName-
-
getTableHeads
获取 Excel 模板中的表头- 参数:
clazz- ExcelModel- 返回:
- excel表头映射
-
buildTableHeads
public static List<TableHead> buildTableHeads(Map<Integer, List<String>> headNameMap, Map<Integer, String> fieldNameMap) 构建 Excel 表头映射- 参数:
headNameMap-fieldNameMap-- 返回:
- 表头映射
-