Excel注解新增 height/width/suffix/defaultValue

This commit is contained in:
RuoYi 2018-11-24 08:54:01 +08:00
parent 1c1078565a
commit 1292dcf579
7 changed files with 40 additions and 17 deletions

View File

@ -19,5 +19,5 @@ public @interface DataScope
/**
* 表的别名
*/
String tableAlias() default "";
public String tableAlias() default "";
}

View File

@ -17,30 +17,50 @@ public @interface Excel
/**
* 导出到Excel中的名字.
*/
public abstract String name();
public String name();
/**
* 日期格式, : yyyy-MM-dd
*/
public abstract String dateFormat() default "";
public String dateFormat() default "";
/**
* 读取内容转表达式 (: 0=,1=,2=未知)
*/
public abstract String readConverterExp() default "";
public String readConverterExp() default "";
/**
* 导出时在excel中每个列的高度 单位为字符
*/
public double height() default 14;
/**
* 导出时在excel中每个列的宽 单位为字符
*/
public double width() default 20;
/**
* 文字后缀,% 90 变成90%
*/
public String suffix() default "";
/**
* 当值为空时,字段的默认值
*/
public String defaultValue() default "";
/**
* 提示信息
*/
public abstract String prompt() default "";
public String prompt() default "";
/**
* 设置只能选择不能输入的列内容.
*/
public abstract String[] combo() default {};
public String[] combo() default {};
/**
* 是否导出数据,应对需求:有时我们需要导出一份模板,这是标题需要但内容需要用户手工填写.
*/
public abstract boolean isExport() default true;
public boolean isExport() default true;
}

View File

@ -21,20 +21,20 @@ public @interface Log
/**
* 模块
*/
String title() default "";
public String title() default "";
/**
* 功能
*/
BusinessType businessType() default BusinessType.OTHER;
public BusinessType businessType() default BusinessType.OTHER;
/**
* 操作人类别
*/
OperatorType operatorType() default OperatorType.MANAGE;
public OperatorType operatorType() default OperatorType.MANAGE;
/**
* 是否保存请求的参数
*/
boolean isSaveRequestData() default true;
public boolean isSaveRequestData() default true;
}

View File

@ -284,7 +284,8 @@ public class ExcelUtil<T>
cellStyle.setFont(font);
cellStyle.setFillForegroundColor(HSSFColorPredefined.LIGHT_YELLOW.getIndex());
// 设置列宽
sheet.setColumnWidth(i, 3766);
sheet.setColumnWidth(i, (int) ((attr.width() + 0.72) * 256));
row.setHeight((short) (attr.height() * 20));
}
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cellStyle.setWrapText(true);
@ -327,6 +328,8 @@ public class ExcelUtil<T>
Excel attr = field.getAnnotation(Excel.class);
try
{
// 设置行高
row.setHeight((short) (attr.height() * 20));
// 根据Excel中设置情况决定是否导出,有些情况需要保持为空,希望用户填写这一列.
if (attr.isExport())
{
@ -354,7 +357,7 @@ public class ExcelUtil<T>
{
cell.setCellType(CellType.STRING);
// 如果数据存在就填入,不存在填入空格.
cell.setCellValue(field.get(vo) == null ? "" : String.valueOf(field.get(vo)));
cell.setCellValue(StringUtils.isNull(field.get(vo)) ? attr.defaultValue() : field.get(vo) + attr.suffix());
}
}
}

View File

@ -48,7 +48,7 @@ public class SysLogininfor extends BaseEntity
private String msg;
/** 访问时间 */
@Excel(name = "访问时间", dateFormat = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "访问时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date loginTime;
public Long getInfoId()

View File

@ -68,7 +68,7 @@ public class SysOperLog extends BaseEntity
private String errorMsg;
/** 操作时间 */
@Excel(name = "操作时间", dateFormat = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date operTime;
public Long getOperId()

View File

@ -67,7 +67,7 @@ public class SysUser extends BaseEntity
private String loginIp;
/** 最后登陆时间 */
@Excel(name = "最后登陆时间", dateFormat = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "最后登陆时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date loginDate;
/** 部门对象 */