public class DefaultExportService extends Object implements ExportService
Excel 导出业务实现
1.0.8: 行高处理
| 限定符和类型 | 字段和说明 |
|---|---|
protected Class<?> |
cls
导出对象类
|
protected ExportTitleParam |
collectionTitleParam
集合列信息, 用于获取集合字段数据
|
protected org.apache.poi.ss.usermodel.CellStyle |
columnTitleStyle
列标题样式
|
protected List<ExportTitleParam> |
contentParams
用于生成内容的参数
|
protected org.apache.poi.ss.usermodel.CellStyle |
contentStyle
内容单元格样式
|
protected int |
crn
当前行号current row number
|
protected List<?> |
datas
需要导出的数据
|
protected int |
maxRowHeight
最大的行高
|
protected org.apache.poi.ss.usermodel.Sheet |
sheet
当前的Sheet
|
protected ExportSheetParam |
sheetParam
导出Sheet的参数
|
protected org.apache.poi.ss.usermodel.CellStyle |
sheetTitleStyle
Sheet标题样式
|
protected List<ExportTitleParam> |
titleParams
用于生成列标题的参数
|
protected org.apache.poi.ss.usermodel.Workbook |
workbook
Excel工作簿
|
| 构造器和说明 |
|---|
DefaultExportService() |
| 限定符和类型 | 方法和说明 |
|---|---|
protected void |
cellMerge(org.apache.poi.ss.usermodel.Row row,
org.apache.poi.ss.usermodel.CellStyle cellStyle,
String value,
int firstRow,
int lastRow,
int firstCol,
int lastCol)
设置单元格合并
|
protected void |
columnTitleCell(org.apache.poi.ss.usermodel.Row row,
int cn,
String title)
设置列标题单元格信息
|
org.apache.poi.ss.usermodel.Workbook |
create(Class<?> cls,
List<?> datas,
ExportSheetParam sheetParam)
创建Excel工作簿
Workbook |
protected List<ExportTitleParam> |
fetchTitleParams(Class<?> cls)
根据实体类型获取需要导出的列参数集合
|
protected void |
fillData()
填充表格数据
|
protected List<ExportTitleParam> |
getCollections(Class<?> cls)
获取集合字段中需要导出的列参数集合
|
protected List<ExportTitleParam> |
getEntities(Class<?> cls)
获取内嵌实体中需要导出的列参数集合
|
protected void |
getFields(Class<?> cls,
Map<String,ExportTitleParam> titleParamMap)
获取字段上定义的需要导出的列信息
|
protected void |
getMethods(Class<?> cls,
Map<String,ExportTitleParam> titleParamMap)
获取公共方法上定义的需要导出的列信息
|
protected void |
handleHasCollection(Object data)
处理实体中有集合时单元格数据
|
protected void |
handleStyle()
处理表格中需要使用到的样式
|
protected void |
handleTitleParams()
处理需要导出列的参数信息
|
protected void |
init(Class<?> cls,
List<?> datas,
ExportSheetParam sheetParam)
初始化传入的参数
|
protected void |
setColumnTitles()
设置列标题
|
protected void |
setColumnTitles(org.apache.poi.ss.usermodel.Row row1,
org.apache.poi.ss.usermodel.Row row2)
设置第一行和第二行的标题信息
|
protected void |
setColumnWidth()
设置列宽
|
protected void |
setContentCellValue(org.apache.poi.ss.usermodel.Row row,
int columnNumber,
String cellValue,
ExportTitleParam titleParam)
设置内容单元格的值
|
protected void |
setRowContent(Object data)
设置行内容
|
protected void |
setRowHeight(org.apache.poi.ss.usermodel.Row row)
设置行高
|
protected void |
setSheetTitle()
设置Sheet标题
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitafterSetColumnTitles, afterSetColumnWidth, afterSetRowContent, afterSetSheetTitle, columnFilter, get, sheet, workbookprotected Class<?> cls
protected List<?> datas
protected org.apache.poi.ss.usermodel.Workbook workbook
protected ExportSheetParam sheetParam
protected List<ExportTitleParam> titleParams
protected List<ExportTitleParam> contentParams
protected int maxRowHeight
protected int crn
protected org.apache.poi.ss.usermodel.Sheet sheet
protected org.apache.poi.ss.usermodel.CellStyle sheetTitleStyle
protected org.apache.poi.ss.usermodel.CellStyle columnTitleStyle
protected org.apache.poi.ss.usermodel.CellStyle contentStyle
protected ExportTitleParam collectionTitleParam
public org.apache.poi.ss.usermodel.Workbook create(Class<?> cls, List<?> datas, ExportSheetParam sheetParam)
ExportServiceWorkbookcreate 在接口中 ExportServicecls - 对象类型datas - 数据集合sheetParam - Sheet的参数protected void fillData()
protected void setRowContent(Object data)
data - 行数据protected void handleHasCollection(Object data)
data - 行数据protected void setRowHeight(org.apache.poi.ss.usermodel.Row row)
row - 指定的行protected void setContentCellValue(org.apache.poi.ss.usermodel.Row row,
int columnNumber,
String cellValue,
ExportTitleParam titleParam)
row - 单元格所在行columnNumber - 单元格所在列cellValue - 单元格的值titleParam - 列参数信息protected void setColumnTitles()
protected void setColumnTitles(org.apache.poi.ss.usermodel.Row row1,
org.apache.poi.ss.usermodel.Row row2)
row1 - 第一行标题的行信息row2 - 第二行标题的行信息protected void columnTitleCell(org.apache.poi.ss.usermodel.Row row,
int cn,
String title)
row - 标题行信息cn - 列号title - 列标题protected void setSheetTitle()
protected void setColumnWidth()
protected void init(Class<?> cls, List<?> datas, ExportSheetParam sheetParam)
cls - 导出对象类型datas - 导出数据集合sheetParam - Sheet的参数protected void cellMerge(org.apache.poi.ss.usermodel.Row row,
org.apache.poi.ss.usermodel.CellStyle cellStyle,
String value,
int firstRow,
int lastRow,
int firstCol,
int lastCol)
row - 行信息cellStyle - 单元格样式value - 单元格的值firstRow - 起始行号lastRow - 终止行号firstCol - 起始列号lastCol - 终止列号protected void handleTitleParams()
protected List<ExportTitleParam> fetchTitleParams(Class<?> cls)
cls - 实体类型protected void getFields(Class<?> cls, Map<String,ExportTitleParam> titleParamMap)
cls - 实体类型titleParamMap - 列信息Mapprotected void getMethods(Class<?> cls, Map<String,ExportTitleParam> titleParamMap)
cls - 实体类型titleParamMap - 列信息Mapprotected List<ExportTitleParam> getEntities(Class<?> cls)
cls - 导出类型protected List<ExportTitleParam> getCollections(Class<?> cls)
cls - 导出类型protected void handleStyle()
Copyright © 2020. All rights reserved.