BigIntegerConverter.java 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package com.izouma.nineth.utils.excel;
  2. import com.alibaba.excel.converters.Converter;
  3. import com.alibaba.excel.enums.CellDataTypeEnum;
  4. import com.alibaba.excel.metadata.CellData;
  5. import com.alibaba.excel.metadata.GlobalConfiguration;
  6. import com.alibaba.excel.metadata.property.ExcelContentProperty;
  7. import java.math.BigInteger;
  8. import java.time.LocalDate;
  9. public class BigIntegerConverter implements Converter<BigInteger> {
  10. @Override
  11. public Class supportJavaTypeKey() {
  12. return BigInteger.class;
  13. }
  14. @Override
  15. public CellDataTypeEnum supportExcelTypeKey() {
  16. return CellDataTypeEnum.STRING;
  17. }
  18. @Override
  19. public BigInteger convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
  20. try {
  21. return BigInteger.valueOf(Long.valueOf(cellData.getStringValue()));
  22. } catch (Exception e) {
  23. }
  24. return null;
  25. }
  26. @Override
  27. public CellData convertToExcelData(BigInteger bigInteger, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
  28. if (bigInteger != null) {
  29. return new CellData(bigInteger.toString());
  30. }
  31. return null;
  32. }
  33. }