Search in sources :

Example 16 with Head

use of com.alibaba.excel.metadata.Head in project easyexcel by alibaba.

the class AbstractWriteHolder method initAnnotationConfig.

protected void initAnnotationConfig(List<WriteHandler> handlerList, WriteBasicParameter writeBasicParameter) {
    if (!HeadKindEnum.CLASS.equals(getExcelWriteHeadProperty().getHeadKind())) {
        return;
    }
    if (writeBasicParameter.getClazz() == null) {
        return;
    }
    Map<Integer, Head> headMap = getExcelWriteHeadProperty().getHeadMap();
    boolean hasColumnWidth = false;
    for (Head head : headMap.values()) {
        if (head.getColumnWidthProperty() != null) {
            hasColumnWidth = true;
        }
        dealLoopMerge(handlerList, head);
    }
    if (hasColumnWidth) {
        dealColumnWidth(handlerList);
    }
    dealStyle(handlerList);
    dealRowHigh(handlerList);
    dealOnceAbsoluteMerge(handlerList);
}
Also used : Head(com.alibaba.excel.metadata.Head)

Example 17 with Head

use of com.alibaba.excel.metadata.Head in project easyexcel by alibaba.

the class WriteContextImpl method addOneRowOfHeadDataToExcel.

private void addOneRowOfHeadDataToExcel(Row row, Integer rowIndex, Map<Integer, Head> headMap, int relativeRowIndex) {
    for (Map.Entry<Integer, Head> entry : headMap.entrySet()) {
        Head head = entry.getValue();
        int columnIndex = entry.getKey();
        ExcelContentProperty excelContentProperty = ClassUtils.declaredExcelContentProperty(null, currentWriteHolder.excelWriteHeadProperty().getHeadClazz(), head.getFieldName());
        CellWriteHandlerContext cellWriteHandlerContext = WriteHandlerUtils.createCellWriteHandlerContext(this, row, rowIndex, head, columnIndex, relativeRowIndex, Boolean.TRUE, excelContentProperty);
        WriteHandlerUtils.beforeCellCreate(cellWriteHandlerContext);
        Cell cell = row.createCell(columnIndex);
        cellWriteHandlerContext.setCell(cell);
        WriteHandlerUtils.afterCellCreate(cellWriteHandlerContext);
        WriteCellData<String> writeCellData = new WriteCellData<>(head.getHeadNameList().get(relativeRowIndex));
        cell.setCellValue(writeCellData.getStringValue());
        cellWriteHandlerContext.setCellDataList(ListUtils.newArrayList(writeCellData));
        cellWriteHandlerContext.setFirstCellData(writeCellData);
        WriteHandlerUtils.afterCellDispose(cellWriteHandlerContext);
    }
}
Also used : Head(com.alibaba.excel.metadata.Head) WriteCellData(com.alibaba.excel.metadata.data.WriteCellData) CellWriteHandlerContext(com.alibaba.excel.write.handler.context.CellWriteHandlerContext) ExcelContentProperty(com.alibaba.excel.metadata.property.ExcelContentProperty) Map(java.util.Map) Cell(org.apache.poi.ss.usermodel.Cell)

Example 18 with Head

use of com.alibaba.excel.metadata.Head in project easyexcel by alibaba.

the class ExcelHeadProperty method initOneColumnProperty.

/**
 * Initialization column property
 *
 * @param index
 * @param field
 * @param forceIndex
 * @return Ignore current field
 */
private void initOneColumnProperty(int index, Field field, Boolean forceIndex) {
    ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class);
    List<String> tmpHeadList = new ArrayList<String>();
    String fieldName = FieldUtils.resolveCglibFieldName(field);
    boolean notForceName = excelProperty == null || excelProperty.value().length <= 0 || (excelProperty.value().length == 1 && StringUtils.isEmpty((excelProperty.value())[0]));
    if (headMap.containsKey(index)) {
        tmpHeadList.addAll(headMap.get(index).getHeadNameList());
    } else {
        if (notForceName) {
            tmpHeadList.add(fieldName);
        } else {
            Collections.addAll(tmpHeadList, excelProperty.value());
        }
    }
    Head head = new Head(index, field, fieldName, tmpHeadList, forceIndex, !notForceName);
    headMap.put(index, head);
}
Also used : Head(com.alibaba.excel.metadata.Head) ExcelProperty(com.alibaba.excel.annotation.ExcelProperty) ArrayList(java.util.ArrayList)

Example 19 with Head

use of com.alibaba.excel.metadata.Head 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

Head (com.alibaba.excel.metadata.Head)19 CellWriteHandlerContext (com.alibaba.excel.write.handler.context.CellWriteHandlerContext)5 AbstractVerticalCellStyleStrategy (com.alibaba.excel.write.style.AbstractVerticalCellStyleStrategy)5 Map (java.util.Map)5 WriteCellStyle (com.alibaba.excel.write.metadata.style.WriteCellStyle)4 WriteFont (com.alibaba.excel.write.metadata.style.WriteFont)4 ExcelContentProperty (com.alibaba.excel.metadata.property.ExcelContentProperty)3 ExcelReadHeadProperty (com.alibaba.excel.read.metadata.property.ExcelReadHeadProperty)3 Cell (org.apache.poi.ss.usermodel.Cell)3 Sheet (org.apache.poi.ss.usermodel.Sheet)3 BeanMap (org.springframework.cglib.beans.BeanMap)3 CellWriteHandler (com.alibaba.excel.write.handler.CellWriteHandler)2 RowWriteHandler (com.alibaba.excel.write.handler.RowWriteHandler)2 SheetWriteHandler (com.alibaba.excel.write.handler.SheetWriteHandler)2 WorkbookWriteHandler (com.alibaba.excel.write.handler.WorkbookWriteHandler)2 WriteHandler (com.alibaba.excel.write.handler.WriteHandler)2 WriteHolder (com.alibaba.excel.write.metadata.holder.WriteHolder)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 TreeMap (java.util.TreeMap)2