use of com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy in project easyexcel by alibaba.
the class StyleDataTest method t03AbstractVerticalCellStyleStrategy.
@Test
public void t03AbstractVerticalCellStyleStrategy() {
AbstractVerticalCellStyleStrategy verticalCellStyleStrategy = new AbstractVerticalCellStyleStrategy() {
@Override
protected WriteCellStyle headCellStyle(Head head) {
WriteCellStyle writeCellStyle = new WriteCellStyle();
writeCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
DataFormatData dataFormatData = new DataFormatData();
dataFormatData.setIndex((short) 0);
writeCellStyle.setDataFormatData(dataFormatData);
writeCellStyle.setHidden(false);
writeCellStyle.setLocked(true);
writeCellStyle.setQuotePrefix(true);
writeCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
writeCellStyle.setWrapped(true);
writeCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
writeCellStyle.setRotation((short) 0);
writeCellStyle.setIndent((short) 10);
writeCellStyle.setBorderLeft(BorderStyle.THIN);
writeCellStyle.setBorderRight(BorderStyle.THIN);
writeCellStyle.setBorderTop(BorderStyle.THIN);
writeCellStyle.setBorderBottom(BorderStyle.THIN);
writeCellStyle.setLeftBorderColor(IndexedColors.RED.getIndex());
writeCellStyle.setRightBorderColor(IndexedColors.RED.getIndex());
writeCellStyle.setTopBorderColor(IndexedColors.RED.getIndex());
writeCellStyle.setBottomBorderColor(IndexedColors.RED.getIndex());
writeCellStyle.setFillBackgroundColor(IndexedColors.RED.getIndex());
writeCellStyle.setShrinkToFit(Boolean.TRUE);
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(fileVerticalCellStyleStrategy07, StyleData.class).registerWriteHandler(verticalCellStyleStrategy).sheet().doWrite(data());
}
use of com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy in project easyexcel by alibaba.
the class AbstractWriteHolder method dealStyle.
private void dealStyle(List<WriteHandler> handlerList) {
WriteHandler styleStrategy = new AbstractVerticalCellStyleStrategy() {
@Override
public int order() {
return OrderConstant.ANNOTATION_DEFINE_STYLE;
}
@Override
protected WriteCellStyle headCellStyle(CellWriteHandlerContext context) {
Head head = context.getHeadData();
if (head == null) {
return null;
}
return WriteCellStyle.build(head.getHeadStyleProperty(), head.getHeadFontProperty());
}
@Override
protected WriteCellStyle contentCellStyle(CellWriteHandlerContext context) {
ExcelContentProperty excelContentProperty = context.getExcelContentProperty();
return WriteCellStyle.build(excelContentProperty.getContentStyleProperty(), excelContentProperty.getContentFontProperty());
}
};
handlerList.add(styleStrategy);
}
use of com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy in project easyexcel by alibaba.
the class FillStyleDataTest method fillStyleHandler.
private void fillStyleHandler(File file, File template) throws Exception {
EasyExcel.write(file, FillStyleData.class).withTemplate(template).sheet().registerWriteHandler(new AbstractVerticalCellStyleStrategy() {
@Override
protected WriteCellStyle contentCellStyle(CellWriteHandlerContext context) {
WriteCellStyle writeCellStyle = new WriteCellStyle();
WriteFont writeFont = new WriteFont();
writeCellStyle.setWriteFont(writeFont);
writeCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
writeFont.setBold(true);
if (context.getColumnIndex() == 0) {
writeCellStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
writeFont.setColor(IndexedColors.DARK_YELLOW.getIndex());
}
if (context.getColumnIndex() == 1) {
writeCellStyle.setFillForegroundColor(IndexedColors.RED.getIndex());
writeFont.setColor(IndexedColors.DARK_RED.getIndex());
}
if (context.getColumnIndex() == 2) {
writeCellStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex());
writeFont.setColor(IndexedColors.DARK_GREEN.getIndex());
}
if (context.getColumnIndex() == 3) {
writeCellStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());
writeFont.setColor(IndexedColors.DARK_BLUE.getIndex());
}
if (context.getColumnIndex() == 4) {
writeCellStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
writeFont.setColor(IndexedColors.DARK_YELLOW.getIndex());
}
if (context.getColumnIndex() == 5) {
writeCellStyle.setFillForegroundColor(IndexedColors.TEAL.getIndex());
writeFont.setColor(IndexedColors.DARK_TEAL.getIndex());
}
return writeCellStyle;
}
@Override
protected WriteCellStyle headCellStyle(Head head) {
return null;
}
}).doFill(data());
}
use of com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy in project easyexcel by alibaba.
the class FillStyleAnnotatedTest method fillStyleHandler.
private void fillStyleHandler(File file, File template) throws Exception {
EasyExcel.write(file, FillData.class).withTemplate(template).sheet().registerWriteHandler(new AbstractVerticalCellStyleStrategy() {
@Override
protected WriteCellStyle contentCellStyle(CellWriteHandlerContext context) {
WriteCellStyle writeCellStyle = new WriteCellStyle();
WriteFont writeFont = new WriteFont();
writeCellStyle.setWriteFont(writeFont);
writeCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
writeFont.setBold(true);
if (context.getColumnIndex() == 0) {
writeCellStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
writeFont.setColor(IndexedColors.DARK_YELLOW.getIndex());
}
if (context.getColumnIndex() == 1) {
writeCellStyle.setFillForegroundColor(IndexedColors.RED.getIndex());
writeFont.setColor(IndexedColors.DARK_RED.getIndex());
}
if (context.getColumnIndex() == 2) {
writeCellStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex());
writeFont.setColor(IndexedColors.DARK_GREEN.getIndex());
}
if (context.getColumnIndex() == 3) {
writeCellStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());
writeFont.setColor(IndexedColors.DARK_BLUE.getIndex());
}
if (context.getColumnIndex() == 4) {
writeCellStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
writeFont.setColor(IndexedColors.DARK_YELLOW.getIndex());
}
if (context.getColumnIndex() == 5) {
writeCellStyle.setFillForegroundColor(IndexedColors.TEAL.getIndex());
writeFont.setColor(IndexedColors.DARK_TEAL.getIndex());
}
return writeCellStyle;
}
@Override
protected WriteCellStyle headCellStyle(Head head) {
return null;
}
}).doFill(data());
}
use of com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy 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());
}
Aggregations