Java Code Examples for com.alibaba.excel.enums.CellDataTypeEnum#EMPTY
The following examples show how to use
com.alibaba.excel.enums.CellDataTypeEnum#EMPTY .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CellData.java From easyexcel with Apache License 2.0 | 6 votes |
/** * Ensure that the object does not appear null */ public void checkEmpty() { if (type == null) { type = CellDataTypeEnum.EMPTY; } switch (type) { case STRING: case ERROR: if (StringUtils.isEmpty(stringValue)) { type = CellDataTypeEnum.EMPTY; } return; case NUMBER: if (numberValue == null) { type = CellDataTypeEnum.EMPTY; } return; case BOOLEAN: if (booleanValue == null) { type = CellDataTypeEnum.EMPTY; } return; default: } }
Example 2
Source File: ConverterUtils.java From easyexcel with Apache License 2.0 | 5 votes |
/** * Convert it into a String map * * @param cellDataMap * @param context * @return */ public static Map<Integer, String> convertToStringMap(Map<Integer, CellData> cellDataMap, AnalysisContext context) { Map<Integer, String> stringMap = new HashMap<Integer, String>(cellDataMap.size() * 4 / 3 + 1); ReadHolder currentReadHolder = context.currentReadHolder(); int index = 0; for (Map.Entry<Integer, CellData> entry : cellDataMap.entrySet()) { Integer key = entry.getKey(); CellData cellData = entry.getValue(); while (index < key) { stringMap.put(index, null); index++; } index++; if (cellData.getType() == CellDataTypeEnum.EMPTY) { stringMap.put(key, null); continue; } Converter converter = currentReadHolder.converterMap().get(ConverterKeyBuild.buildKey(String.class, cellData.getType())); if (converter == null) { throw new ExcelDataConvertException(context.readRowHolder().getRowIndex(), key, cellData, null, "Converter not found, convert " + cellData.getType() + " to String"); } try { stringMap.put(key, (String)(converter.convertToJavaData(cellData, null, currentReadHolder.globalConfiguration()))); } catch (Exception e) { throw new ExcelDataConvertException(context.readRowHolder().getRowIndex(), key, cellData, null, "Convert data " + cellData + " to String error ", e); } } return stringMap; }
Example 3
Source File: AbstractExcelWriteExecutor.java From easyexcel with Apache License 2.0 | 5 votes |
protected CellData converterAndSet(WriteHolder currentWriteHolder, Class clazz, Cell cell, Object value, ExcelContentProperty excelContentProperty, Head head, Integer relativeRowIndex) { if (value == null) { return new CellData(CellDataTypeEnum.EMPTY); } if (value instanceof String && currentWriteHolder.globalConfiguration().getAutoTrim()) { value = ((String)value).trim(); } CellData cellData = convert(currentWriteHolder, clazz, cell, value, excelContentProperty); if (cellData.getFormula() != null && cellData.getFormula()) { cell.setCellFormula(cellData.getFormulaValue()); } if (cellData.getType() == null) { cellData.setType(CellDataTypeEnum.EMPTY); } WriteHandlerUtils.afterCellDataConverted(writeContext, cellData, cell, head, relativeRowIndex, Boolean.FALSE); switch (cellData.getType()) { case STRING: cell.setCellValue(cellData.getStringValue()); return cellData; case BOOLEAN: cell.setCellValue(cellData.getBooleanValue()); return cellData; case NUMBER: cell.setCellValue(cellData.getNumberValue().doubleValue()); return cellData; case IMAGE: setImageValue(cellData, cell); return cellData; case EMPTY: return cellData; default: throw new ExcelDataConvertException(cell.getRow().getRowNum(), cell.getColumnIndex(), cellData, excelContentProperty, "Not supported data:" + value + " return type:" + cell.getCellType() + "at row:" + cell.getRow().getRowNum()); } }
Example 4
Source File: AbstractExcelWriteExecutor.java From easyexcel with Apache License 2.0 | 5 votes |
protected CellData convert(WriteHolder currentWriteHolder, Class clazz, Cell cell, Object value, ExcelContentProperty excelContentProperty) { if (value == null) { return new CellData(CellDataTypeEnum.EMPTY); } // This means that the user has defined the data. if (value instanceof CellData) { CellData cellDataValue = (CellData)value; if (cellDataValue.getType() != null) { return cellDataValue; } else { if (cellDataValue.getData() == null) { cellDataValue.setType(CellDataTypeEnum.EMPTY); return cellDataValue; } } CellData cellDataReturn = doConvert(currentWriteHolder, cellDataValue.getData().getClass(), cell, cellDataValue.getData(), excelContentProperty); // The formula information is subject to user input if (cellDataValue.getFormula() != null) { cellDataReturn.setFormula(cellDataValue.getFormula()); cellDataReturn.setFormulaValue(cellDataValue.getFormulaValue()); } return cellDataReturn; } return doConvert(currentWriteHolder, clazz, cell, value, excelContentProperty); }
Example 5
Source File: AbstractExcelWriteExecutor.java From easyexcel with Apache License 2.0 | 5 votes |
private CellData doConvert(WriteHolder currentWriteHolder, Class clazz, Cell cell, Object value, ExcelContentProperty excelContentProperty) { Converter converter = null; if (excelContentProperty != null) { converter = excelContentProperty.getConverter(); } if (converter == null) { converter = currentWriteHolder.converterMap().get(ConverterKeyBuild.buildKey(clazz)); } if (converter == null) { throw new ExcelDataConvertException(cell.getRow().getRowNum(), cell.getColumnIndex(), new CellData(CellDataTypeEnum.EMPTY), excelContentProperty, "Can not find 'Converter' support class " + clazz.getSimpleName() + "."); } CellData cellData; try { cellData = converter.convertToExcelData(value, excelContentProperty, currentWriteHolder.globalConfiguration()); } catch (Exception e) { throw new ExcelDataConvertException(cell.getRow().getRowNum(), cell.getColumnIndex(), new CellData(CellDataTypeEnum.EMPTY), excelContentProperty, "Convert data:" + value + " error,at row:" + cell.getRow().getRowNum(), e); } if (cellData == null || cellData.getType() == null) { throw new ExcelDataConvertException(cell.getRow().getRowNum(), cell.getColumnIndex(), new CellData(CellDataTypeEnum.EMPTY), excelContentProperty, "Convert data:" + value + " return null,at row:" + cell.getRow().getRowNum()); } return cellData; }
Example 6
Source File: ModelBuildEventListener.java From easyexcel with Apache License 2.0 | 5 votes |
private Object buildUserModel(Map<Integer, CellData> cellDataMap, ReadHolder currentReadHolder, AnalysisContext context) { ExcelReadHeadProperty excelReadHeadProperty = currentReadHolder.excelReadHeadProperty(); Object resultModel; try { resultModel = excelReadHeadProperty.getHeadClazz().newInstance(); } catch (Exception e) { throw new ExcelDataConvertException(context.readRowHolder().getRowIndex(), 0, new CellData(CellDataTypeEnum.EMPTY), null, "Can not instance class: " + excelReadHeadProperty.getHeadClazz().getName(), e); } Map<Integer, Head> headMap = excelReadHeadProperty.getHeadMap(); Map<String, Object> map = new HashMap<String, Object>(headMap.size() * 4 / 3 + 1); Map<Integer, ExcelContentProperty> contentPropertyMap = excelReadHeadProperty.getContentPropertyMap(); for (Map.Entry<Integer, Head> entry : headMap.entrySet()) { Integer index = entry.getKey(); if (!cellDataMap.containsKey(index)) { continue; } CellData cellData = cellDataMap.get(index); if (cellData.getType() == CellDataTypeEnum.EMPTY) { continue; } ExcelContentProperty excelContentProperty = contentPropertyMap.get(index); Object value = ConverterUtils.convertToJavaObject(cellData, excelContentProperty.getField(), excelContentProperty, currentReadHolder.converterMap(), currentReadHolder.globalConfiguration(), context.readRowHolder().getRowIndex(), index); if (value != null) { map.put(excelContentProperty.getField().getName(), value); } } BeanMap.create(resultModel).putAll(map); return resultModel; }
Example 7
Source File: CellData.java From easyexcel with Apache License 2.0 | 4 votes |
public static CellData newEmptyInstance(Integer rowIndex, Integer columnIndex) { CellData cellData = new CellData(CellDataTypeEnum.EMPTY); cellData.setRowIndex(rowIndex); cellData.setColumnIndex(columnIndex); return cellData; }