com.alibaba.excel.metadata.GlobalConfiguration Java Examples
The following examples show how to use
com.alibaba.excel.metadata.GlobalConfiguration.
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: StringNumberConverter.java From easyexcel with Apache License 2.0 | 6 votes |
@Override public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { // If there are "DateTimeFormat", read as date if (contentProperty != null && contentProperty.getDateTimeFormatProperty() != null) { return DateUtils.format( DateUtil.getJavaDate(cellData.getNumberValue().doubleValue(), contentProperty.getDateTimeFormatProperty().getUse1904windowing(), null), contentProperty.getDateTimeFormatProperty().getFormat()); } // If there are "NumberFormat", read as number if (contentProperty != null && contentProperty.getNumberFormatProperty() != null) { return NumberUtils.format(cellData.getNumberValue(), contentProperty); } // Excel defines formatting if (cellData.getDataFormat() != null && !StringUtils.isEmpty(cellData.getDataFormatString())) { return NumberDataFormatterUtils.format(cellData.getNumberValue().doubleValue(), cellData.getDataFormat(), cellData.getDataFormatString(), globalConfiguration); } // Default conversion number return NumberUtils.format(cellData.getNumberValue(), contentProperty); }
Example #2
Source File: DataFormatter.java From easyexcel with Apache License 2.0 | 6 votes |
/** * Creates a formatter using the given locale. * */ public DataFormatter(GlobalConfiguration globalConfiguration) { if (globalConfiguration == null) { this.use1904windowing = Boolean.FALSE; this.locale = Locale.getDefault(); this.useScientificFormat = Boolean.FALSE; } else { this.use1904windowing = globalConfiguration.getUse1904windowing() != null ? globalConfiguration.getUse1904windowing() : Boolean.FALSE; this.locale = globalConfiguration.getLocale() != null ? globalConfiguration.getLocale() : Locale.getDefault(); this.useScientificFormat = globalConfiguration.getUseScientificFormat() != null ? globalConfiguration.getUseScientificFormat() : Boolean.FALSE; } this.dateSymbols = DateFormatSymbols.getInstance(this.locale); this.decimalSymbols = DecimalFormatSymbols.getInstance(this.locale); }
Example #3
Source File: ConverterUtils.java From easyexcel with Apache License 2.0 | 6 votes |
/** * * @param cellData * @param clazz * @param contentProperty * @param converterMap * @param globalConfiguration * @param rowIndex * @param columnIndex * @return */ private static Object doConvertToJavaObject(CellData cellData, Class clazz, ExcelContentProperty contentProperty, Map<String, Converter> converterMap, GlobalConfiguration globalConfiguration, Integer rowIndex, Integer columnIndex) { Converter converter = null; if (contentProperty != null) { converter = contentProperty.getConverter(); } if (converter == null) { converter = converterMap.get(ConverterKeyBuild.buildKey(clazz, cellData.getType())); } if (converter == null) { throw new ExcelDataConvertException(rowIndex, columnIndex, cellData, contentProperty, "Converter not found, convert " + cellData.getType() + " to " + clazz.getName()); } try { return converter.convertToJavaData(cellData, contentProperty, globalConfiguration); } catch (Exception e) { throw new ExcelDataConvertException(rowIndex, columnIndex, cellData, contentProperty, "Convert data " + cellData + " to " + clazz + " error ", e); } }
Example #4
Source File: EnumExcelConverter.java From easyexcel-utils with Apache License 2.0 | 6 votes |
@Override public CellData convertToExcelData(Enum value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { String enumName = value.name(); EnumFormat annotation = contentProperty.getField().getAnnotation(EnumFormat.class); String[] fromExcel = annotation.fromExcel(); String[] toJavaEnum = annotation.toJavaEnum(); if (ArrayUtils.isNotEmpty(fromExcel) && ArrayUtils.isNotEmpty(toJavaEnum)) { Assert.isTrue(fromExcel.length == toJavaEnum.length, "fromExcel 与 toJavaEnum 的长度必须相同"); for (int i = 0; i < toJavaEnum.length; i++) { if (Objects.equals(toJavaEnum[i], enumName)) { return new CellData(fromExcel[i]); } } } return new CellData(enumName); }
Example #5
Source File: EnumExcelConverter.java From easyexcel-utils with Apache License 2.0 | 6 votes |
@Override public Enum convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { String cellDataStr = cellData.getStringValue(); EnumFormat annotation = contentProperty.getField().getAnnotation(EnumFormat.class); Class enumClazz = annotation.value(); String[] fromExcel = annotation.fromExcel(); String[] toJavaEnum = annotation.toJavaEnum(); Enum anEnum = null; if (ArrayUtils.isNotEmpty(fromExcel) && ArrayUtils.isNotEmpty(toJavaEnum)) { Assert.isTrue(fromExcel.length == toJavaEnum.length, "fromExcel 与 toJavaEnum 的长度必须相同"); for (int i = 0; i < fromExcel.length; i++) { if (Objects.equals(fromExcel[i], cellDataStr)) { anEnum = EnumUtils.getEnum(enumClazz, toJavaEnum[i]); } } } else { anEnum = EnumUtils.getEnum(enumClazz, cellDataStr); } Assert.notNull(anEnum, "枚举值不合法"); return anEnum; }
Example #6
Source File: DoubleBooleanConverter.java From easyexcel with Apache License 2.0 | 5 votes |
@Override public CellData convertToExcelData(Double value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (ONE.equals(value)) { return new CellData(Boolean.TRUE); } return new CellData(Boolean.FALSE); }
Example #7
Source File: DisabledConverter.java From fw-spring-cloud with Apache License 2.0 | 5 votes |
@Override public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception { String stringValue = cellData.getStringValue(); if (ENABLE.equals(stringValue.trim())){ return 0; }else { return 1; } }
Example #8
Source File: BoxingByteArrayImageConverter.java From easyexcel with Apache License 2.0 | 5 votes |
@Override public CellData convertToExcelData(Byte[] value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { byte[] byteValue = new byte[value.length]; for (int i = 0; i < value.length; i++) { byteValue[i] = value[i]; } return new CellData(byteValue); }
Example #9
Source File: DisabledConverter.java From fw-spring-cloud with Apache License 2.0 | 5 votes |
@Override public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception { String stringValue = cellData.getStringValue(); if (ENABLE.equals(stringValue.trim())){ return 0; }else { return 1; } }
Example #10
Source File: ShortBooleanConverter.java From easyexcel with Apache License 2.0 | 5 votes |
@Override public Short convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (cellData.getBooleanValue()) { return ONE; } return ZERO; }
Example #11
Source File: ShortBooleanConverter.java From easyexcel with Apache License 2.0 | 5 votes |
@Override public CellData convertToExcelData(Short value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (ONE.equals(value)) { return new CellData(Boolean.TRUE); } return new CellData(Boolean.FALSE); }
Example #12
Source File: DateNumberConverter.java From easyexcel with Apache License 2.0 | 5 votes |
@Override public CellData convertToExcelData(Date value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { return new CellData( BigDecimal.valueOf(DateUtil.getExcelDate(value, globalConfiguration.getUse1904windowing()))); } else { return new CellData(BigDecimal.valueOf( DateUtil.getExcelDate(value, contentProperty.getDateTimeFormatProperty().getUse1904windowing()))); } }
Example #13
Source File: ReadRowHolder.java From easyexcel with Apache License 2.0 | 5 votes |
public ReadRowHolder(Integer rowIndex, RowTypeEnum rowType, GlobalConfiguration globalConfiguration, Map<Integer, Cell> cellMap) { this.rowIndex = rowIndex; this.rowType = rowType; this.globalConfiguration = globalConfiguration; this.cellMap = cellMap; }
Example #14
Source File: DeleteConverter.java From fw-spring-cloud with Apache License 2.0 | 5 votes |
@Override public CellData convertToExcelData(Integer integer, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception { if (integer==0){ return new CellData(NOT_DELETE); }else { return new CellData(DELETE); } }
Example #15
Source File: DisabledConverter.java From fw-spring-cloud with Apache License 2.0 | 5 votes |
@Override public CellData convertToExcelData(Integer integer, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception { if (integer==0){ return new CellData(ENABLE); }else { return new CellData(NOT_ENABLE); } }
Example #16
Source File: DeleteConverter.java From fw-spring-cloud with Apache License 2.0 | 5 votes |
@Override public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception { String stringValue = cellData.getStringValue(); if (DELETE.equals(stringValue)){ return 1; }else { return 0; } }
Example #17
Source File: DisabledConverter.java From fw-spring-cloud with Apache License 2.0 | 5 votes |
@Override public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception { String stringValue = cellData.getStringValue(); if (ENABLE.equals(stringValue.trim())){ return 0; }else { return 1; } }
Example #18
Source File: DisabledConverter.java From fw-spring-cloud with Apache License 2.0 | 5 votes |
@Override public CellData convertToExcelData(Integer integer, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception { if (integer==0){ return new CellData(ENABLE); }else { return new CellData(NOT_ENABLE); } }
Example #19
Source File: UrlImageConverter.java From easyexcel with Apache License 2.0 | 5 votes |
@Override public CellData convertToExcelData(URL value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws IOException { InputStream inputStream = null; try { inputStream = value.openStream(); byte[] bytes = IoUtils.toByteArray(inputStream); return new CellData(bytes); } finally { if (inputStream != null) { inputStream.close(); } } }
Example #20
Source File: NumberDataFormatterUtils.java From easyexcel with Apache License 2.0 | 5 votes |
/** * Format number data. * * @param data * @param dataFormat Not null. * @param dataFormatString * @param globalConfiguration * @return */ public static String format(Double data, Integer dataFormat, String dataFormatString, GlobalConfiguration globalConfiguration) { DataFormatter dataFormatter = DATA_FORMATTER_THREAD_LOCAL.get(); if (dataFormatter == null) { dataFormatter = new DataFormatter(globalConfiguration); DATA_FORMATTER_THREAD_LOCAL.set(dataFormatter); } return dataFormatter.format(data, dataFormat, dataFormatString); }
Example #21
Source File: ConverterUtils.java From easyexcel with Apache License 2.0 | 5 votes |
/** * Convert it into a Java object * * @param cellData * @param field * @param contentProperty * @param converterMap * @param globalConfiguration * @param rowIndex * @param columnIndex * @return */ public static Object convertToJavaObject(CellData cellData, Field field, ExcelContentProperty contentProperty, Map<String, Converter> converterMap, GlobalConfiguration globalConfiguration, Integer rowIndex, Integer columnIndex) { Class clazz; if (field == null) { clazz = String.class; } else { clazz = field.getType(); } if (clazz == CellData.class) { Type type = field.getGenericType(); Class classGeneric; if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType)type; classGeneric = (Class)parameterizedType.getActualTypeArguments()[0]; } else { classGeneric = String.class; } CellData cellDataReturn = new CellData(cellData); cellDataReturn.setData(doConvertToJavaObject(cellData, classGeneric, contentProperty, converterMap, globalConfiguration, rowIndex, columnIndex)); return cellDataReturn; } return doConvertToJavaObject(cellData, clazz, contentProperty, converterMap, globalConfiguration, rowIndex, columnIndex); }
Example #22
Source File: LongBooleanConverter.java From easyexcel with Apache License 2.0 | 5 votes |
@Override public Long convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (cellData.getBooleanValue()) { return ONE; } return ZERO; }
Example #23
Source File: LongBooleanConverter.java From easyexcel with Apache License 2.0 | 5 votes |
@Override public CellData convertToExcelData(Long value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (ONE.equals(value)) { return new CellData(Boolean.TRUE); } return new CellData(Boolean.FALSE); }
Example #24
Source File: ByteBooleanConverter.java From easyexcel with Apache License 2.0 | 5 votes |
@Override public CellData convertToExcelData(Byte value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (ONE.equals(value)) { return new CellData(Boolean.TRUE); } return new CellData(Boolean.FALSE); }
Example #25
Source File: ByteBooleanConverter.java From easyexcel with Apache License 2.0 | 5 votes |
@Override public Byte convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (cellData.getBooleanValue()) { return ONE; } return ZERO; }
Example #26
Source File: FloatBooleanConverter.java From easyexcel with Apache License 2.0 | 5 votes |
@Override public Float convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (cellData.getBooleanValue()) { return ONE; } return ZERO; }
Example #27
Source File: DateStringConverter.java From easyexcel with Apache License 2.0 | 5 votes |
@Override public CellData convertToExcelData(Date value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (contentProperty == null || contentProperty.getDateTimeFormatProperty() == null) { return new CellData(DateUtils.format(value, null)); } else { return new CellData(DateUtils.format(value, contentProperty.getDateTimeFormatProperty().getFormat())); } }
Example #28
Source File: IntegerBooleanConverter.java From easyexcel with Apache License 2.0 | 5 votes |
@Override public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { if (cellData.getBooleanValue()) { return ONE; } return ZERO; }
Example #29
Source File: InputStreamImageConverter.java From easyexcel with Apache License 2.0 | 4 votes |
@Override public InputStream convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { throw new UnsupportedOperationException("Cannot convert images to input stream"); }
Example #30
Source File: BooleanBooleanConverter.java From easyexcel with Apache License 2.0 | 4 votes |
@Override public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) { return cellData.getBooleanValue(); }