import java.lang.annotation.*;@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
public @interface ExcelStyle {int width() default 0;
}
/*** 聊天记录*/
@Data
public class DialogContentInfo {/*** 群ID*/@Alias("群ID")@ExcelStyle(width = 30)private String dialogId;/*** 患者群名*/@Alias("患者群名")@ExcelStyle(width = 80)private String dialogTitle;/*** 内容*/@Alias("消息内容")@ExcelStyle(width = 120)private String content;/*** 发送人*/@Alias("随访人员")@ExcelStyle(width = 25)private String nickname;/*** 时间*/@Alias("时间")@ExcelStyle(width = 25)private String createdTime;/*** userId*/@PropIgnoreprivate Long userId;
}
/*** 设置excel样式*/private void setExcelStyle(Class<?> clazz, ExcelWriter writer) {Field[] fields = ClassUtil.getDeclaredFields(clazz);for (int index = 0; index < fields.length; index++) {Field field = fields[index];ExcelStyle excelStyle = field.getAnnotation(ExcelStyle.class);if (excelStyle == null || excelStyle.width() == 0) {continue;}writer.setColumnWidth(index, excelStyle.width());}}