更新日志
2020-07-04
插入图片的功能更新
@ExcelPicture注解调整单元格下标命名,使其含义更加明确
@ExcelPicture注解新增pictureType参数,用来确定图片的格式
@ExcelPicture调整x,y坐标值的计算方式,现在只需要将x,y设置成单元格的像素值
E-POI
该项目主要以通过注解的方式将一个实体类变成一个2007版excel的sheet。在生成工作表前你的首先创建一个工作薄(XSSFWorkbook)
注解说明
类注解
@ExcelSheet
当类定义了该注解后即可依据该类定义的注解生成Excel的sheet。当然了,这其中还是需要配合字段的注解才能生成一个比较完整的sheet。
参数
类型
默认值
说明
inventorySheet
boolean
false
用来说明被注解类的对象在生成excel文件时是否为清单文件,所谓清单文件即指如同数据库的一张表
name
String
sheet
工作表的名称,如果工作表名称出现重复则自动以定义的名称+序号创建新的名称
horizontallyCenter
boolean
true
设置页面在打印时是否水平居中
verticallyCenter
boolean
true
设置页面在打印时是否垂直居中
topMargin
double
0.984252
上边距,以英寸为单位
bottomMargin
double
0.984252
下边距,以英寸为单位
leftMargin
double
0.7480315
左边距,以英寸为单位
rightMargin
double
0.7480315
右边距,以英寸为单位
使用方法:
@ExcelSheet(name="测试工作表",leftMargin = 0.1968504, rightMargin = 0.1968504, verticallyCenter = false)
public class TestEntity{}
@ExcelPrint
该注解主要是为了便于定义工作表的打印参数,该注解单独使用无效,必须配合**@ExcelSheet**一起使用
参数
类型
默认值
说明
landscape
boolean
false
打印方向,false:纵向,true:横向
paperSize
short
PrintSetup.A4_EXTRA_PAPERSIZE
纸张格式,直接使用poi中PrintSetup接口所定义的一些常量
scale
short
100
缩放比例
vResolution
short
300
垂直分辨率
使用方法:
@ExcelSheet(name="测试工作表",leftMargin = 0.1968504, rightMargin = 0.1968504, verticallyCenter = false)
@ExcelPrint(landscape = true, scale = 81)
public class TestEntity{}
字段注解
@ExcelCell
如果定义了@ExcelSheet的类中的字段需要在sheet中显示其内容,则需要定义该注解。该注解定义了一个单元格,该单元格可以是合并的,也可以是非合并的,单元格的内容即为字段的内容。注意:该注解在父类中生效
参数
类型
默认值
说明
rowHeight
float
13.5f
行高。一般如果有多个字段在一行内,则只需给其中一个字段定义行高即可。(注意:如果字段的行定义在同一行内且都定义的行高,则一般以最后一个字段定义的行高为最终行高)
columnWidth
float
8.38f
列宽,实际列宽可能有细微的差异,但差异不大。一般如果有多个字段在一列内,则只需给其中一个字段定义列宽即可。(注意:如果字段的行定义在同一列下且都定义的列宽,则一般以最后一个字段定义的列宽为最终列宽)
rowIndex
int
0
行的index
columnIndex
int
0
列的index
nullValue
String
当字段值为null时单元格的内容
booleanTrueValue
String
当字段值为boolean型且值为true时单元格的内容
booleanFalseValue
String
当字段值为boolean型且值为false时单元格的内容
excelCellStyle
@ExcelCellStyle
@ExcelCellStyle
单元格样式,参见@ExcelCellStyle注解
excelCellMerged
@ExcelCellMerged
@ExcelCellMerged
单元格合并方式,参见@ExcelCellMerged注解
使用方法:
@ExcelSheet(name="测试工作表",leftMargin = 0.1968504, rightMargin = 0.1968504, verticallyCenter = false)
@ExcelPrint(landscape = true, scale = 81)
public class TestEntity{
@ExcelCell(
rowHeight=16.58f,
columnWidth = 10.5f,
rowIndex=0,
columnIndex = 1,
nullValue="/"
)
private String testField;
@ExcelCell(
rowHeight=16.58f,
columnWidth = 10.5f,
rowIndex=0,
columnIndex = 1,
nullValue="/",
booleanTrueValue = "√",
booleanFalseValue = "×"
)
private Boolean testBooleanField;
}
@ExcelCellStyle
该注解用来定义单元格的样式。
参数
类型
默认值
说明
horizontalAlignment
HorizontalAlignment
HorizontalAlignment.CENTER
水平对齐方式
verticalAlignment
VerticalAlignment
VerticalAlignment.CENTER
垂直对齐方式
borderLeft
BorderStyle
BorderStyle.NONE
左边框样式
borderRight
BorderStyle
BorderStyle.NONE
右边框样式
borderTop
BorderStyle
BorderStyle.NONE
上边框样式
borderBottom
BorderStyle
BorderStyle.NONE
下边框样式
wrapText
boolean
false
单元格文本是否自动换行。false:不换行,true:换行
excelCellFont
@ExcelCellFont
@ExcelCellFont
单元格字体,参见@ExcelCellFont注解
使用方法:
@ExcelSheet(name = "测试工作表", leftMargin = 0.1968504, rightMargin = 0.1968504, verticallyCenter = false)
@ExcelPrint(landscape = tr