Search in sources :

Example 1 with WriteSheetHolder

use of com.alibaba.excel.write.metadata.holder.WriteSheetHolder in project easyexcel by alibaba.

the class WriteContextImpl method initCurrentSheetHolder.

private void initCurrentSheetHolder(WriteSheet writeSheet) {
    writeSheetHolder = new WriteSheetHolder(writeSheet, writeWorkbookHolder);
    writeTableHolder = null;
    currentWriteHolder = writeSheetHolder;
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("CurrentConfiguration is writeSheetHolder");
    }
}
Also used : WriteSheetHolder(com.alibaba.excel.write.metadata.holder.WriteSheetHolder)

Example 2 with WriteSheetHolder

use of com.alibaba.excel.write.metadata.holder.WriteSheetHolder in project easyexcel by alibaba.

the class ExcelWriteAddExecutor method initSortedAllFieldMapFieldList.

private void initSortedAllFieldMapFieldList(Class<?> clazz, Map<Integer, Field> sortedAllFieldMap) {
    if (!sortedAllFieldMap.isEmpty()) {
        return;
    }
    WriteSheetHolder writeSheetHolder = writeContext.writeSheetHolder();
    boolean needIgnore = !CollectionUtils.isEmpty(writeSheetHolder.getExcludeColumnFieldNames()) || !CollectionUtils.isEmpty(writeSheetHolder.getExcludeColumnIndexes()) || !CollectionUtils.isEmpty(writeSheetHolder.getIncludeColumnFieldNames()) || !CollectionUtils.isEmpty(writeSheetHolder.getIncludeColumnIndexes());
    ClassUtils.declaredFields(clazz, sortedAllFieldMap, needIgnore, writeSheetHolder);
}
Also used : WriteSheetHolder(com.alibaba.excel.write.metadata.holder.WriteSheetHolder)

Example 3 with WriteSheetHolder

use of com.alibaba.excel.write.metadata.holder.WriteSheetHolder in project easyexcel by alibaba.

the class DimensionWorkbookWriteHandler method afterWorkbookDispose.

@Override
public void afterWorkbookDispose(WriteWorkbookHolder writeWorkbookHolder) {
    if (writeWorkbookHolder == null || writeWorkbookHolder.getWorkbook() == null) {
        return;
    }
    if (!(writeWorkbookHolder.getWorkbook() instanceof SXSSFWorkbook)) {
        return;
    }
    Map<Integer, WriteSheetHolder> writeSheetHolderMap = writeWorkbookHolder.getHasBeenInitializedSheetIndexMap();
    if (MapUtils.isEmpty(writeSheetHolderMap)) {
        return;
    }
    for (WriteSheetHolder writeSheetHolder : writeSheetHolderMap.values()) {
        if (writeSheetHolder.getSheet() == null || !(writeSheetHolder.getSheet() instanceof SXSSFSheet)) {
            continue;
        }
        SXSSFSheet sxssfSheet = ((SXSSFSheet) writeSheetHolder.getSheet());
        XSSFSheet xssfSheet;
        try {
            xssfSheet = (XSSFSheet) XSSF_SHEET_FIELD.get(sxssfSheet);
        } catch (IllegalAccessException e) {
            log.debug("Can not found _sh.", e);
            continue;
        }
        if (xssfSheet == null) {
            continue;
        }
        CTWorksheet ctWorksheet = xssfSheet.getCTWorksheet();
        if (ctWorksheet == null) {
            continue;
        }
        int headSize = 0;
        if (MapUtils.isNotEmpty(writeSheetHolder.getExcelWriteHeadProperty().getHeadMap())) {
            headSize = writeSheetHolder.getExcelWriteHeadProperty().getHeadMap().size();
            if (headSize > 0) {
                headSize--;
            }
        }
        Integer lastRowIndex = writeSheetHolder.getLastRowIndex();
        if (lastRowIndex == null) {
            lastRowIndex = 0;
        }
        ctWorksheet.getDimension().setRef("A1:" + CellReference.convertNumToColString(headSize) + (lastRowIndex + 1));
    }
}
Also used : SXSSFSheet(org.apache.poi.xssf.streaming.SXSSFSheet) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) SXSSFWorkbook(org.apache.poi.xssf.streaming.SXSSFWorkbook) CTWorksheet(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet) WriteSheetHolder(com.alibaba.excel.write.metadata.holder.WriteSheetHolder) SXSSFSheet(org.apache.poi.xssf.streaming.SXSSFSheet)

Example 4 with WriteSheetHolder

use of com.alibaba.excel.write.metadata.holder.WriteSheetHolder in project easyexcel by alibaba.

the class ExcelWriteAddExecutor method add.

public void add(Collection<?> data) {
    if (CollectionUtils.isEmpty(data)) {
        data = new ArrayList<>();
    }
    WriteSheetHolder writeSheetHolder = writeContext.writeSheetHolder();
    int newRowIndex = writeSheetHolder.getNewRowIndexAndStartDoWrite();
    if (writeSheetHolder.isNew() && !writeSheetHolder.getExcelWriteHeadProperty().hasHead()) {
        newRowIndex += writeContext.currentWriteHolder().relativeHeadRowIndex();
    }
    // BeanMap is out of order, so use sortedAllFieldMap
    Map<Integer, Field> sortedAllFieldMap = new TreeMap<>();
    int relativeRowIndex = 0;
    for (Object oneRowData : data) {
        int lastRowIndex = relativeRowIndex + newRowIndex;
        addOneRowOfDataToExcel(oneRowData, lastRowIndex, relativeRowIndex, sortedAllFieldMap);
        relativeRowIndex++;
    }
}
Also used : Field(java.lang.reflect.Field) WriteSheetHolder(com.alibaba.excel.write.metadata.holder.WriteSheetHolder) TreeMap(java.util.TreeMap)

Aggregations

WriteSheetHolder (com.alibaba.excel.write.metadata.holder.WriteSheetHolder)4 Field (java.lang.reflect.Field)1 TreeMap (java.util.TreeMap)1 SXSSFSheet (org.apache.poi.xssf.streaming.SXSSFSheet)1 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)1 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)1 CTWorksheet (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet)1