Search in sources :

Example 1 with FontProperty

use of com.alibaba.excel.metadata.property.FontProperty in project easyexcel by alibaba.

the class StyleDataTest method t04AbstractVerticalCellStyleStrategy02.

@Test
public void t04AbstractVerticalCellStyleStrategy02() {
    final StyleProperty styleProperty = StyleProperty.build(StyleData.class.getAnnotation(HeadStyle.class));
    final FontProperty fontProperty = FontProperty.build(StyleData.class.getAnnotation(HeadFontStyle.class));
    AbstractVerticalCellStyleStrategy verticalCellStyleStrategy = new AbstractVerticalCellStyleStrategy() {

        @Override
        protected WriteCellStyle headCellStyle(Head head) {
            WriteCellStyle writeCellStyle = WriteCellStyle.build(styleProperty, fontProperty);
            if (head.getColumnIndex() == 0) {
                writeCellStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
                WriteFont writeFont = new WriteFont();
                writeFont.setItalic(true);
                writeFont.setStrikeout(true);
                writeFont.setTypeOffset(Font.SS_NONE);
                writeFont.setUnderline(Font.U_DOUBLE);
                writeFont.setBold(true);
                writeFont.setCharset((int) Font.DEFAULT_CHARSET);
            } else {
                writeCellStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());
            }
            return writeCellStyle;
        }

        @Override
        protected WriteCellStyle contentCellStyle(Head head) {
            WriteCellStyle writeCellStyle = new WriteCellStyle();
            writeCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
            if (head.getColumnIndex() == 0) {
                writeCellStyle.setFillForegroundColor(IndexedColors.DARK_GREEN.getIndex());
            } else {
                writeCellStyle.setFillForegroundColor(IndexedColors.PINK.getIndex());
            }
            return writeCellStyle;
        }
    };
    EasyExcel.write(fileVerticalCellStyleStrategy207, StyleData.class).registerWriteHandler(verticalCellStyleStrategy).sheet().doWrite(data());
}
Also used : StyleProperty(com.alibaba.excel.metadata.property.StyleProperty) FontProperty(com.alibaba.excel.metadata.property.FontProperty) AbstractVerticalCellStyleStrategy(com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy) Head(com.alibaba.excel.metadata.Head) WriteCellStyle(com.alibaba.excel.write.metadata.style.WriteCellStyle) WriteFont(com.alibaba.excel.write.metadata.style.WriteFont) HeadFontStyle(com.alibaba.excel.annotation.write.style.HeadFontStyle) HeadStyle(com.alibaba.excel.annotation.write.style.HeadStyle) Test(org.junit.Test)

Aggregations

HeadFontStyle (com.alibaba.excel.annotation.write.style.HeadFontStyle)1 HeadStyle (com.alibaba.excel.annotation.write.style.HeadStyle)1 Head (com.alibaba.excel.metadata.Head)1 FontProperty (com.alibaba.excel.metadata.property.FontProperty)1 StyleProperty (com.alibaba.excel.metadata.property.StyleProperty)1 WriteCellStyle (com.alibaba.excel.write.metadata.style.WriteCellStyle)1 WriteFont (com.alibaba.excel.write.metadata.style.WriteFont)1 AbstractVerticalCellStyleStrategy (com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy)1 Test (org.junit.Test)1