com.feilong.lib.excel.convertor.IntegerConvertor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of feilong Show documentation
Show all versions of feilong Show documentation
feilong is a suite of core and expanded libraries that include utility classes, http, excel,cvs, io classes, and much much more.
package com.feilong.lib.excel.convertor;
import static com.feilong.core.bean.ConvertUtil.toInteger;
import com.feilong.excel.ExcelException;
import com.feilong.excel.definition.ExcelCell;
/**
* 解决 12344.0 转成 int 的问题
*
* @author feilong
* @since 1.13.2
*/
public class IntegerConvertor extends AbstractChoiceConvertor{
@Override
protected Integer convertValue(int sheetNo,String cellIndex,ExcelCell excelCell,Object value){
if (value instanceof String){
String str = (String) value;
str = str.trim();
if (str.length() == 0){
if (!excelCell.isMandatory()){
return null;
}
throw new ExcelException(WRONG_DATA_NULL, sheetNo, cellIndex, null, excelCell);
}
//---------------------------------------------------------------
try{
return toInteger(value);
}catch (Exception e){
throw new ExcelException(WRONG_DATA_TYPE_NUMBER, sheetNo, cellIndex, value, excelCell);
}
}else if (value instanceof Double){
return (int) Math.rint((Double) value);
}
throw new ExcelException(WRONG_DATA_TYPE_NUMBER, sheetNo, cellIndex, value, excelCell);
}
//---------------------------------------------------------------
@Override
public String getDataTypeAbbr(){
return "integer";
}
@Override
public Class supportClass(){
return Integer.class;
}
}