public class ExcelUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
private static org.apache.logging.log4j.Logger |
LOG |
| 限定符 | 构造器和说明 |
|---|---|
private |
ExcelUtil()
私有
|
| 限定符和类型 | 方法和说明 |
|---|---|
private static void |
cellMerge(org.apache.poi.ss.usermodel.Sheet sheet,
int firstRow,
int lastRow,
int firstCol,
int lastCol)
合并单元格
|
static org.apache.poi.ss.usermodel.Workbook |
createBigWorkbook(int rowAccessWindowSize)
创建大数据workBook
避免OOM,导出速度比较慢
默认后缀 xlsx
|
private static org.apache.poi.ss.usermodel.DataValidation |
createCustomValidation(org.apache.poi.ss.usermodel.Sheet sheet,
String formula,
String info,
int col,
int maxRow,
int lastRow)
excel添加自定义校验
|
private static org.apache.poi.ss.usermodel.DataValidation |
createDateValidation(org.apache.poi.ss.usermodel.Sheet sheet,
String pattern,
String start,
String end,
String info,
int col,
int maxRow,
int lastRow)
excel添加时间数据校验
|
private static org.apache.poi.ss.usermodel.DataValidation |
createDropDownValidation(org.apache.poi.ss.usermodel.Sheet sheet,
String[] dataSource,
int col,
int firstRow,
int lastRow)
excel添加下拉数据校验
|
static org.apache.poi.ss.usermodel.Workbook |
createEmptyWorkbook(boolean xlsx)
创建空的workBook,做循环填充用
|
private static org.apache.poi.ss.usermodel.DataValidation |
createFloatValidation(org.apache.poi.ss.usermodel.Sheet sheet,
String minNum,
String maxNum,
String info,
int col,
int maxRow,
int lastRow)
excel添加数字校验
|
private static org.apache.poi.ss.usermodel.DataValidation |
createNumValidation(org.apache.poi.ss.usermodel.Sheet sheet,
String minNum,
String maxNum,
String info,
int col,
int maxRow,
int lastRow)
excel添加数字校验
|
private static org.apache.poi.ss.usermodel.DataValidation |
createTextLengthValidation(org.apache.poi.ss.usermodel.Sheet sheet,
String minNum,
String maxNum,
String info,
int col,
int maxRow,
int lastRow)
excel添加文本字符长度校验
|
static void |
encryptWorkbook03(org.apache.poi.ss.usermodel.Workbook workbook,
String password)
给工作簿加密码
|
static <T> void |
export(OutputStream out,
List<T> data,
ExportRules exportRules)
导出
|
static void |
export(org.apache.poi.ss.usermodel.Workbook workbook,
javax.servlet.http.HttpServletResponse response,
String fileName,
String password)
导出
|
static void |
export(org.apache.poi.ss.usermodel.Workbook workbook,
OutputStream outputStream,
String password)
导出
|
static void |
export(org.apache.poi.ss.usermodel.Workbook workbook,
String outPath,
String password)
导出
|
static <T> void |
fillBook(org.apache.poi.ss.usermodel.Workbook wb,
List<T> data,
ExportRules exportRules)
填充wb,循环填充为多个Sheet
|
private static Object |
getCellValue(org.apache.poi.ss.usermodel.Row r,
int cellNum,
org.apache.poi.ss.usermodel.FormulaEvaluator formulaEvaluator)
获取单元格的值
|
(专用程序包) static OutputStream |
getDownloadStream(javax.servlet.http.HttpServletResponse response,
String fileName)
获取导出Excel的流
|
private static int[] |
getFooterNum(List<ComplexCell> entries,
int currRowNum)
根据页脚数据获得行号
|
private static int |
getLastRealLastRow(org.apache.poi.ss.usermodel.Row row)
获取真实的数据行
|
private static Map<String,org.apache.poi.ss.usermodel.PictureData> |
getSheetPictures(int sheetNum,
org.apache.poi.ss.usermodel.Sheet sheet)
获取Excel2003图片
|
private static Map<String,org.apache.poi.ss.usermodel.PictureData> |
getSheetPictures03(int sheetNum,
org.apache.poi.hssf.usermodel.HSSFSheet sheet)
获取Excel2003图片
|
private static Map<String,org.apache.poi.ss.usermodel.PictureData> |
getSheetPictures07(int sheetNum,
org.apache.poi.xssf.usermodel.XSSFSheet sheet)
获取Excel2007图片
|
private static <T> void |
handleColumnProperty(List<T> data,
ExportRules exportRules,
org.apache.poi.ss.usermodel.Sheet sheet)
列属性设置
|
private static void |
handleComplexHeader(ExportRules exportRules,
org.apache.poi.ss.usermodel.Font titleFont,
org.apache.poi.ss.usermodel.CellStyle titleStyleSource,
ICellStyle titleStyle,
org.apache.poi.ss.usermodel.Font headerFont,
org.apache.poi.ss.usermodel.CellStyle headerStyleSource,
ICellStyle headerStyle,
org.apache.poi.ss.usermodel.Sheet sheet)
复杂表头设计
|
private static <T> void |
handleFooter(List<T> data,
ExportRules exportRules,
org.apache.poi.ss.usermodel.Font footerFont,
org.apache.poi.ss.usermodel.CellStyle footerStyleSource,
ICellStyle footerStyle,
org.apache.poi.ss.usermodel.Sheet sheet)
footer设置
|
private static ICellStyle |
handleGlobalStyle(ICellStyle[] globalStyle,
org.apache.poi.ss.usermodel.Font font,
org.apache.poi.ss.usermodel.CellStyle cellStyle,
CellPosition cellPosition)
全局样式处理
|
private static org.apache.poi.ss.usermodel.DataValidation |
handleMultiVersion(String info,
org.apache.poi.ss.util.CellRangeAddressList cellRangeAddressList,
org.apache.poi.ss.usermodel.DataValidationHelper helper,
org.apache.poi.ss.usermodel.DataValidationConstraint constraint)
兼容性问题处理
|
private static void |
handleSimpleHeader(ExportRules exportRules,
org.apache.poi.ss.usermodel.Font titleFont,
org.apache.poi.ss.usermodel.CellStyle titleStyleSource,
ICellStyle titleStyle,
org.apache.poi.ss.usermodel.Font headerFont,
org.apache.poi.ss.usermodel.CellStyle headerStyleSource,
ICellStyle headerStyle,
org.apache.poi.ss.usermodel.Sheet sheet)
简单表头设计
|
static void |
printSetup(org.apache.poi.ss.usermodel.Sheet sheet)
设置打印方向
|
static org.apache.poi.ss.usermodel.Workbook |
readExcelWrite(InputStream is,
Map<String,String> variable)
读取excel,替换内置变量
|
static org.apache.poi.ss.usermodel.Workbook |
readExcelWrite(InputStream is,
String password,
Map<String,String> variable)
读取excel,替换内置变量
|
static org.apache.poi.ss.usermodel.Workbook |
readExcelWrite(String filePath,
Map<String,String> variable)
读取excel,替换内置变量
|
static org.apache.poi.ss.usermodel.Workbook |
readExcelWrite(String filePath,
String password,
Map<String,String> variable)
读取excel,替换内置变量
|
private static org.apache.poi.ss.usermodel.Workbook |
readExcelWrite(org.apache.poi.ss.usermodel.Workbook workbook,
Map<String,String> variable)
读取excel,替换内置变量
|
private static Object |
readField(Map<Class<?>,Map<String,Field>> clsInfo,
Object t,
String fields)
读取字段的值
|
private static Object |
readObjectFieldValue(Object t,
String key,
Map<Class<?>,Map<String,Field>> clsInfo)
读取object的属性
|
static <T> PoiResult<T> |
readSheet(InputStream is,
PoiSheetDataArea poiSheetArea,
Map<String,InColumn<?>> columns,
InCallback<T> callBack,
Class<T> rowClass)
读取规则excel数据内容为map
|
static <T> PoiResult<T> |
readSheet(InputStream is,
String password,
PoiSheetDataArea poiSheetArea,
Map<String,InColumn<?>> columns,
InCallback<T> callBack,
Class<T> rowClass)
读取规则excel数据内容为map
|
static <T> PoiResult<T> |
readSheet(org.apache.poi.ss.usermodel.Sheet sheet,
int dataStartRow,
int dataEndRowCount,
Map<String,InColumn<?>> columns,
InCallback<T> callBack,
Class<T> rowClass)
读取规则excel数据内容为map
|
static <T> PoiResult<T> |
readSheet(String filePath,
PoiSheetDataArea poiSheetArea,
Map<String,InColumn<?>> columns,
InCallback<T> callBack,
Class<T> rowClass)
读取规则excel数据内容为map
|
static <T> PoiResult<T> |
readSheet(String filePath,
String password,
PoiSheetDataArea poiSheetArea,
Map<String,InColumn<?>> columns,
InCallback<T> callBack,
Class<T> rowClass)
读取规则excel数据内容为map
|
private static org.apache.poi.ss.usermodel.Drawing<?> |
safeCreateDrawing(org.apache.poi.ss.usermodel.Sheet sheet)
同步创建drawing
|
private static org.apache.poi.ss.usermodel.Sheet |
safeCreateSheet(org.apache.poi.ss.usermodel.Workbook wb,
String sheetName)
同步创建sheet
|
private static void |
setCellComment(org.apache.poi.ss.usermodel.Drawing<?> createDrawingPatriarch,
org.apache.poi.ss.usermodel.Cell cell,
String comment)
设置单元格的批注
|
private static void |
setCellStyle(org.apache.poi.ss.usermodel.Workbook wb,
org.apache.poi.ss.usermodel.Font cellFont,
Map<String,org.apache.poi.ss.usermodel.CellStyle> cacheStyle,
Map<String,org.apache.poi.ss.usermodel.Font> cacheFont,
OutColumn.Style styleCustom,
org.apache.poi.ss.usermodel.Cell cell,
Object value)
处理单元格样式
|
private static void |
setCellValue(org.apache.poi.ss.usermodel.Drawing<?> createDrawingPatriarch,
Object value,
org.apache.poi.ss.usermodel.Cell cell)
给单元格设置值
|
public static void printSetup(org.apache.poi.ss.usermodel.Sheet sheet)
sheet - sheet页public static void encryptWorkbook03(org.apache.poi.ss.usermodel.Workbook workbook,
String password)
workbook - 工作簿password - 密码public static org.apache.poi.ss.usermodel.Workbook createBigWorkbook(int rowAccessWindowSize)
默认后缀 xlsx
rowAccessWindowSize - 在内存中的行数public static org.apache.poi.ss.usermodel.Workbook createEmptyWorkbook(boolean xlsx)
xlsx - 是否为xlsx格式static OutputStream getDownloadStream(javax.servlet.http.HttpServletResponse response, String fileName)
response - 响应流fileName - 文件名public static void export(org.apache.poi.ss.usermodel.Workbook workbook,
javax.servlet.http.HttpServletResponse response,
String fileName,
String password)
workbook - 工作簿response - 响应password - 文件密码fileName - 文件名public static <T> void export(OutputStream out, List<T> data, ExportRules exportRules)
out - 导出流data - 数据源exportRules - 导出规则public static void export(org.apache.poi.ss.usermodel.Workbook workbook,
String outPath,
String password)
workbook - 工作簿outPath - 删除目录password - 文件密码public static void export(org.apache.poi.ss.usermodel.Workbook workbook,
OutputStream outputStream,
String password)
workbook - 工作簿outputStream - 流public static <T> void fillBook(org.apache.poi.ss.usermodel.Workbook wb,
List<T> data,
ExportRules exportRules)
wb - 工作簿data - 数据exportRules - 导出规则private static void setCellComment(org.apache.poi.ss.usermodel.Drawing<?> createDrawingPatriarch,
org.apache.poi.ss.usermodel.Cell cell,
String comment)
createDrawingPatriarch - 画图器cell - 单元格comment - 批注内容private static org.apache.poi.ss.usermodel.Drawing<?> safeCreateDrawing(org.apache.poi.ss.usermodel.Sheet sheet)
sheet - sheetprivate static org.apache.poi.ss.usermodel.Sheet safeCreateSheet(org.apache.poi.ss.usermodel.Workbook wb,
String sheetName)
wb - 工作簿sheetName - sheet名字private static void setCellStyle(org.apache.poi.ss.usermodel.Workbook wb,
org.apache.poi.ss.usermodel.Font cellFont,
Map<String,org.apache.poi.ss.usermodel.CellStyle> cacheStyle,
Map<String,org.apache.poi.ss.usermodel.Font> cacheFont,
OutColumn.Style styleCustom,
org.apache.poi.ss.usermodel.Cell cell,
Object value)
wb - 工作簿cellFont - 原字体cacheStyle - 缓存样式cacheFont - 缓存字体styleCustom - 样式cell - 单元格value - 值private static <T> void handleFooter(List<T> data, ExportRules exportRules, org.apache.poi.ss.usermodel.Font footerFont, org.apache.poi.ss.usermodel.CellStyle footerStyleSource, ICellStyle footerStyle, org.apache.poi.ss.usermodel.Sheet sheet)
data - 数据exportRules - 导出规则footerFont - fontfooterStyleSource - stylesheet - sheetfooterStyle - 全局样式private static <T> void handleColumnProperty(List<T> data, ExportRules exportRules, org.apache.poi.ss.usermodel.Sheet sheet)
data - 数据exportRules - 导出规则sheet - sheetprivate static void handleSimpleHeader(ExportRules exportRules, org.apache.poi.ss.usermodel.Font titleFont, org.apache.poi.ss.usermodel.CellStyle titleStyleSource, ICellStyle titleStyle, org.apache.poi.ss.usermodel.Font headerFont, org.apache.poi.ss.usermodel.CellStyle headerStyleSource, ICellStyle headerStyle, org.apache.poi.ss.usermodel.Sheet sheet)
exportRules - 导出规则titleFont - 大标题字体titleStyleSource - 大标题样式titleStyle - 大标题自定义样式处理headerFont - 标题字体headerStyleSource - 标题样式headerStyle - 标题自定义样式处理sheet - sheetprivate static void handleComplexHeader(ExportRules exportRules, org.apache.poi.ss.usermodel.Font titleFont, org.apache.poi.ss.usermodel.CellStyle titleStyleSource, ICellStyle titleStyle, org.apache.poi.ss.usermodel.Font headerFont, org.apache.poi.ss.usermodel.CellStyle headerStyleSource, ICellStyle headerStyle, org.apache.poi.ss.usermodel.Sheet sheet)
exportRules - 导出规则titleFont - 大标题字体titleStyleSource - 大标题样式titleStyle - 大标题自定义样式处理headerFont - 标题字体headerStyleSource - 标题样式headerStyle - 标题自定义样式处理sheet - sheetprivate static void cellMerge(org.apache.poi.ss.usermodel.Sheet sheet,
int firstRow,
int lastRow,
int firstCol,
int lastCol)
sheet - sheetfirstRow - 卡死行lastRow - 结束行firstCol - 开始列lastCol - 结束列private static ICellStyle handleGlobalStyle(ICellStyle[] globalStyle, org.apache.poi.ss.usermodel.Font font, org.apache.poi.ss.usermodel.CellStyle cellStyle, CellPosition cellPosition)
globalStyle - 全局样式font - 字体cellStyle - 样式cellPosition - 位置public static <T> PoiResult<T> readSheet(String filePath, PoiSheetDataArea poiSheetArea, Map<String,InColumn<?>> columns, InCallback<T> callBack, Class<T> rowClass)
filePath - 文件路径poiSheetArea - 数据区域columns - 数据列定义callBack - 回调数据行rowClass - 数据类public static <T> PoiResult<T> readSheet(String filePath, String password, PoiSheetDataArea poiSheetArea, Map<String,InColumn<?>> columns, InCallback<T> callBack, Class<T> rowClass)
filePath - 文件路径poiSheetArea - 数据区域columns - 数据列定义callBack - 回调数据行rowClass - 数据类public static <T> PoiResult<T> readSheet(InputStream is, PoiSheetDataArea poiSheetArea, Map<String,InColumn<?>> columns, InCallback<T> callBack, Class<T> rowClass)
is - 文件流poiSheetArea - 数据区域columns - 数据列定义callBack - 回调数据行rowClass - 数据类public static <T> PoiResult<T> readSheet(InputStream is, String password, PoiSheetDataArea poiSheetArea, Map<String,InColumn<?>> columns, InCallback<T> callBack, Class<T> rowClass)
is - 文件流poiSheetArea - 数据区域columns - 数据列定义callBack - 回调数据行rowClass - 数据类public static <T> PoiResult<T> readSheet(org.apache.poi.ss.usermodel.Sheet sheet, int dataStartRow, int dataEndRowCount, Map<String,InColumn<?>> columns, InCallback<T> callBack, Class<T> rowClass)
sheet - sheet页dataStartRow - 起始行dataEndRowCount - 尾部非数据行数量public static org.apache.poi.ss.usermodel.Workbook readExcelWrite(String filePath, Map<String,String> variable)
filePath - 文件路径variable - 内置变量public static org.apache.poi.ss.usermodel.Workbook readExcelWrite(String filePath, String password, Map<String,String> variable)
filePath - 文件路径password - 文件密码variable - 内置变量public static org.apache.poi.ss.usermodel.Workbook readExcelWrite(InputStream is, Map<String,String> variable)
is - excel文件流variable - 内置变量public static org.apache.poi.ss.usermodel.Workbook readExcelWrite(InputStream is, String password, Map<String,String> variable)
is - excel文件流password - 文件密码variable - 内置变量private static org.apache.poi.ss.usermodel.Workbook readExcelWrite(org.apache.poi.ss.usermodel.Workbook workbook,
Map<String,String> variable)
workbook - excel对象variable - 内置变量private static int getLastRealLastRow(org.apache.poi.ss.usermodel.Row row)
row - 单元格private static Object readField(Map<Class<?>,Map<String,Field>> clsInfo, Object t, String fields)
clsInfo - 类信息t - 当前值fields - 字段名称private static Object readObjectFieldValue(Object t, String key, Map<Class<?>,Map<String,Field>> clsInfo)
t - 对象key - field字段clsInfo - 类信息private static void setCellValue(org.apache.poi.ss.usermodel.Drawing<?> createDrawingPatriarch,
Object value,
org.apache.poi.ss.usermodel.Cell cell)
createDrawingPatriarch - 画图器value - 单元格值cell - 单元格private static int[] getFooterNum(List<ComplexCell> entries, int currRowNum)
entries - 规则currRowNum - 当前行private static Object getCellValue(org.apache.poi.ss.usermodel.Row r, int cellNum, org.apache.poi.ss.usermodel.FormulaEvaluator formulaEvaluator)
r - 当前行cellNum - 单元格号private static Map<String,org.apache.poi.ss.usermodel.PictureData> getSheetPictures(int sheetNum, org.apache.poi.ss.usermodel.Sheet sheet)
sheetNum - 当前sheet下标sheet - 当前sheet对象private static Map<String,org.apache.poi.ss.usermodel.PictureData> getSheetPictures03(int sheetNum, org.apache.poi.hssf.usermodel.HSSFSheet sheet)
sheetNum - 当前sheet编号sheet - 当前sheet对象private static Map<String,org.apache.poi.ss.usermodel.PictureData> getSheetPictures07(int sheetNum, org.apache.poi.xssf.usermodel.XSSFSheet sheet)
sheetNum - 当前sheet编号sheet - 当前sheet对象private static org.apache.poi.ss.usermodel.DataValidation createDropDownValidation(org.apache.poi.ss.usermodel.Sheet sheet,
String[] dataSource,
int col,
int firstRow,
int lastRow)
sheet - 哪个 sheet 页添加校验dataSource - 数据源数组col - 第几列校验(0开始)firstRow - 开始行lastRow - 结束行private static org.apache.poi.ss.usermodel.DataValidation createDateValidation(org.apache.poi.ss.usermodel.Sheet sheet,
String pattern,
String start,
String end,
String info,
int col,
int maxRow,
int lastRow)
throws Exception
sheet - 哪个 sheet 页添加校验start - 開始end - 结束info - 提示信息col - 第几列校验(0开始)maxRow - 表头占用几行Exceptionprivate static org.apache.poi.ss.usermodel.DataValidation handleMultiVersion(String info, org.apache.poi.ss.util.CellRangeAddressList cellRangeAddressList, org.apache.poi.ss.usermodel.DataValidationHelper helper, org.apache.poi.ss.usermodel.DataValidationConstraint constraint)
info - 提示消息cellRangeAddressList - 地址helper - 验证器constraint - 验证private static org.apache.poi.ss.usermodel.DataValidation createNumValidation(org.apache.poi.ss.usermodel.Sheet sheet,
String minNum,
String maxNum,
String info,
int col,
int maxRow,
int lastRow)
sheet - 哪个 sheet 页添加校验minNum - 最小值maxNum - 最大值info - 提示信息col - 第几列校验(0开始)maxRow - 表头占用几行private static org.apache.poi.ss.usermodel.DataValidation createFloatValidation(org.apache.poi.ss.usermodel.Sheet sheet,
String minNum,
String maxNum,
String info,
int col,
int maxRow,
int lastRow)
sheet - 哪个 sheet 页添加校验minNum - 最小值maxNum - 最大值col - 第几列校验(0开始)maxRow - 表头占用几行private static org.apache.poi.ss.usermodel.DataValidation createTextLengthValidation(org.apache.poi.ss.usermodel.Sheet sheet,
String minNum,
String maxNum,
String info,
int col,
int maxRow,
int lastRow)
sheet - 哪个 sheet 页添加校验minNum - 最小值maxNum - 最大值info - 自定义提示col - 第几列校验(0开始)maxRow - 表头占用几行private static org.apache.poi.ss.usermodel.DataValidation createCustomValidation(org.apache.poi.ss.usermodel.Sheet sheet,
String formula,
String info,
int col,
int maxRow,
int lastRow)
sheet - 哪个 sheet 页添加校验formula - 表达式col - 第几列校验(0开始)maxRow - 表头占用几行Copyright © 2023. All rights reserved.