Search in sources :

Example 6 with AnalysisCell

use of com.alibaba.excel.write.metadata.fill.AnalysisCell in project easyexcel by alibaba.

the class ExcelWriteFillExecutor method initAnalysisCell.

private AnalysisCell initAnalysisCell(Integer rowIndex, Integer columnIndex) {
    AnalysisCell analysisCell = new AnalysisCell();
    analysisCell.setRowIndex(rowIndex);
    analysisCell.setColumnIndex(columnIndex);
    analysisCell.setOnlyOneVariable(Boolean.TRUE);
    List<String> variableList = ListUtils.newArrayList();
    analysisCell.setVariableList(variableList);
    List<String> prepareDataList = ListUtils.newArrayList();
    analysisCell.setPrepareDataList(prepareDataList);
    analysisCell.setCellType(WriteTemplateAnalysisCellTypeEnum.COMMON);
    analysisCell.setFirstRow(Boolean.FALSE);
    return analysisCell;
}
Also used : AnalysisCell(com.alibaba.excel.write.metadata.fill.AnalysisCell)

Example 7 with AnalysisCell

use of com.alibaba.excel.write.metadata.fill.AnalysisCell in project easyexcel by alibaba.

the class ExcelWriteFillExecutor method readTemplateData.

private List<AnalysisCell> readTemplateData(Map<UniqueDataFlagKey, List<AnalysisCell>> analysisCache) {
    List<AnalysisCell> analysisCellList = analysisCache.get(currentUniqueDataFlag);
    if (analysisCellList != null) {
        return analysisCellList;
    }
    Sheet sheet = writeContext.writeSheetHolder().getCachedSheet();
    Map<UniqueDataFlagKey, Set<Integer>> firstRowCache = MapUtils.newHashMapWithExpectedSize(8);
    for (int i = 0; i <= sheet.getLastRowNum(); i++) {
        Row row = sheet.getRow(i);
        if (row == null) {
            continue;
        }
        for (int j = 0; j < row.getLastCellNum(); j++) {
            Cell cell = row.getCell(j);
            if (cell == null) {
                continue;
            }
            String preparedData = prepareData(cell, i, j, firstRowCache);
            // Prevent empty data from not being replaced
            if (preparedData != null) {
                cell.setCellValue(preparedData);
            }
        }
    }
    return analysisCache.get(currentUniqueDataFlag);
}
Also used : AnalysisCell(com.alibaba.excel.write.metadata.fill.AnalysisCell) HashSet(java.util.HashSet) Set(java.util.Set) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) AnalysisCell(com.alibaba.excel.write.metadata.fill.AnalysisCell) Cell(org.apache.poi.ss.usermodel.Cell)

Aggregations

AnalysisCell (com.alibaba.excel.write.metadata.fill.AnalysisCell)7 Sheet (org.apache.poi.ss.usermodel.Sheet)4 Cell (org.apache.poi.ss.usermodel.Cell)3 Row (org.apache.poi.ss.usermodel.Row)3 ExcelGenerateException (com.alibaba.excel.exception.ExcelGenerateException)2 FillWrapper (com.alibaba.excel.write.metadata.fill.FillWrapper)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 CellStyle (org.apache.poi.ss.usermodel.CellStyle)2 WriteContext (com.alibaba.excel.context.WriteContext)1 CellDataTypeEnum (com.alibaba.excel.enums.CellDataTypeEnum)1 WriteDirectionEnum (com.alibaba.excel.enums.WriteDirectionEnum)1 WriteTemplateAnalysisCellTypeEnum (com.alibaba.excel.enums.WriteTemplateAnalysisCellTypeEnum)1 WriteCellData (com.alibaba.excel.metadata.data.WriteCellData)1 ExcelContentProperty (com.alibaba.excel.metadata.property.ExcelContentProperty)1 BeanMapUtils (com.alibaba.excel.util.BeanMapUtils)1 ClassUtils (com.alibaba.excel.util.ClassUtils)1 FieldUtils (com.alibaba.excel.util.FieldUtils)1 ListUtils (com.alibaba.excel.util.ListUtils)1