Search in sources :

Example 1 with MapRowData

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

the class ExcelWriteAddExecutor method addOneRowOfDataToExcel.

private void addOneRowOfDataToExcel(Object oneRowData, int rowIndex, int relativeRowIndex, Map<Integer, Field> sortedAllFieldMap) {
    if (oneRowData == null) {
        return;
    }
    RowWriteHandlerContext rowWriteHandlerContext = WriteHandlerUtils.createRowWriteHandlerContext(writeContext, rowIndex, relativeRowIndex, Boolean.FALSE);
    WriteHandlerUtils.beforeRowCreate(rowWriteHandlerContext);
    Row row = WorkBookUtil.createRow(writeContext.writeSheetHolder().getSheet(), rowIndex);
    rowWriteHandlerContext.setRow(row);
    WriteHandlerUtils.afterRowCreate(rowWriteHandlerContext);
    if (oneRowData instanceof Collection<?>) {
        addBasicTypeToExcel(new CollectionRowData((Collection<?>) oneRowData), row, rowIndex, relativeRowIndex);
    } else if (oneRowData instanceof Map) {
        addBasicTypeToExcel(new MapRowData((Map<Integer, ?>) oneRowData), row, rowIndex, relativeRowIndex);
    } else {
        addJavaObjectToExcel(oneRowData, row, rowIndex, relativeRowIndex, sortedAllFieldMap);
    }
    WriteHandlerUtils.afterRowDispose(rowWriteHandlerContext);
}
Also used : RowWriteHandlerContext(com.alibaba.excel.write.handler.context.RowWriteHandlerContext) MapRowData(com.alibaba.excel.write.metadata.MapRowData) CollectionRowData(com.alibaba.excel.write.metadata.CollectionRowData) Collection(java.util.Collection) Row(org.apache.poi.ss.usermodel.Row) BeanMap(org.springframework.cglib.beans.BeanMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

RowWriteHandlerContext (com.alibaba.excel.write.handler.context.RowWriteHandlerContext)1 CollectionRowData (com.alibaba.excel.write.metadata.CollectionRowData)1 MapRowData (com.alibaba.excel.write.metadata.MapRowData)1 Collection (java.util.Collection)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Row (org.apache.poi.ss.usermodel.Row)1 BeanMap (org.springframework.cglib.beans.BeanMap)1