easyexcel 列宽、行高、样式
程序员文章站
2024-01-08 13:02:16
...
easyexcel 列宽、行高、样式
**********************
相关注解
HeadRowHeight:标注在类上
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface HeadRowHeight {
short value() default -1;
}
ContentRowHeight:标注在类上
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface ContentRowHeight {
short value() default -1;
}
ColumnWidth:标注在类、字段上,列宽
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface ColumnWidth {
int value() default -1;
}
HeadStyle:标注在类、字段上
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface HeadStyle {
short dataFormat() default -1;
short rotation() default -1;
short indent() default -1;
boolean hidden() default false;
boolean locked() default true;
boolean quotePrefix() default false;
boolean wrapped() default true;
boolean shrinkToFit() default false;
BorderStyle borderLeft() default BorderStyle.THIN;
BorderStyle borderRight() default BorderStyle.THIN;
BorderStyle borderTop() default BorderStyle.THIN;
BorderStyle borderBottom() default BorderStyle.THIN;
short leftBorderColor() default -1;
short rightBorderColor() default -1;
short topBorderColor() default -1;
short bottomBorderColor() default -1;
short fillBackgroundColor() default -1;
short fillForegroundColor() default -1;
HorizontalAlignment horizontalAlignment() default HorizontalAlignment.CENTER;
VerticalAlignment verticalAlignment() default VerticalAlignment.CENTER;
FillPatternType fillPatternType() default FillPatternType.SOLID_FOREGROUND;
}
HeadFontStyle:标注在类、字段上
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface HeadFontStyle {
byte underline() default -1;
short color() default -1;
short typeOffset() default -1;
short fontHeightInPoints() default 14;
int charset() default -1;
String fontName() default "宋体";
boolean italic() default false;
boolean strikeout() default false;
boolean bold() default true;
}
ContentStyle
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface ContentStyle {
short dataFormat() default -1;
short rotation() default -1;
short indent() default -1;
short fillBackgroundColor() default -1;
short fillForegroundColor() default -1;
boolean hidden() default false;
boolean locked() default false;
boolean quotePrefix() default false;
boolean wrapped() default false;
boolean shrinkToFit() default false;
BorderStyle borderLeft() default BorderStyle.NONE;
BorderStyle borderRight() default BorderStyle.NONE;
BorderStyle borderTop() default BorderStyle.NONE;
BorderStyle borderBottom() default BorderStyle.NONE;
short leftBorderColor() default -1;
short rightBorderColor() default -1;
short topBorderColor() default -1;
short bottomBorderColor() default -1;
FillPatternType fillPatternType() default FillPatternType.NO_FILL;
VerticalAlignment verticalAlignment() default VerticalAlignment.CENTER;
HorizontalAlignment horizontalAlignment() default HorizontalAlignment.GENERAL;
}
ContentFontStyle
@Target({ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface ContentFontStyle {
byte underline() default -1;
short color() default -1;
short typeOffset() default -1;
short fontHeightInPoints() default -1;
int charset() default -1;
String fontName() default "";
boolean italic() default false;
boolean strikeout() default false;
boolean bold() default false;
}
**********************
示例
*****************
head 类
Fruit
@Data
@HeadRowHeight(40)
@ContentRowHeight(20)
public class Fruit {
@ColumnWidth(10)
private Integer id;
@ContentStyle(fillPatternType = FillPatternType.SOLID_FOREGROUND ,fillForegroundColor = 6)
private String name;
@HeadFontStyle(color = 20)
private Double price;
}
*****************
测试类
Test
public class Test5 {
private static final String file_path="e:"+ File.separator+"java"+File.separator+"easyexcel"+File.separator+"write_test9.xlsx";
public static void main(String[] args){
List<Fruit> list=new ArrayList<>();
Fruit fruit=new Fruit();
fruit.setId(1);
fruit.setName("apple");
fruit.setPrice(10d);
list.add(fruit);
EasyExcel.write(file_path,Fruit.class).sheet().doWrite(list);
}
}
**********************
使用测试
推荐阅读
-
easyexcel 列宽、行高、样式
-
文本有关的样式和jQuery求对象的高宽问题分别说明
-
详解C#设置Excel数据自适应行高、列宽的2种情况
-
腾讯文档表格怎么设置行高和列宽?
-
WPS表格怎么调整行高、列宽、多列的列宽以及最适合列宽
-
在Word2003表格中设置行高和列宽
-
canvas设置像素与画布样式宽高不符的原因及解决办法
-
POI单元格样式、行高列宽、合并单元格设置
-
php导出excel图片格式,PHPExcel API接口用法大全,按模板导入excel,美化excel,导出图片,设置单元格字体颜色背景色边框,合并单元格,设置行高列宽...
-
Python使用OpenPyXl设置Excel表格中的单元格大小(行高和列宽)