easyexcel 列宽、行高、样式

x33g5p2x  于2021-12-28 转载在 其他  
字(3.9k)|赞(0)|评价(0)|浏览(1248)

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);
    }
}

**********************

使用测试

                 

相关文章