LongStringConverter.java 1.21 KB
package com.taover.easyexcel.converters.longconverter;

import java.text.ParseException;

import com.taover.easyexcel.converters.Converter;
import com.taover.easyexcel.enums.CellDataTypeEnum;
import com.taover.easyexcel.metadata.CellData;
import com.taover.easyexcel.metadata.GlobalConfiguration;
import com.taover.easyexcel.metadata.property.ExcelContentProperty;
import com.taover.easyexcel.util.NumberUtils;

/**
 * Long and string converter
 *
 * @author Jiaju Zhuang
 */
public class LongStringConverter implements Converter<Long> {

    @Override
    public Class supportJavaTypeKey() {
        return Long.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public Long convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
        GlobalConfiguration globalConfiguration) throws ParseException {
        return NumberUtils.parseLong(cellData.getStringValue(), contentProperty);
    }

    @Override
    public CellData convertToExcelData(Long value, ExcelContentProperty contentProperty,
        GlobalConfiguration globalConfiguration) {
        return NumberUtils.formatToCellData(value, contentProperty);
    }
}