解决Excel导入时整数数字变成小数(double类型)的问题


方法:

private String numberFormat(Cell cell){
        NumberFormat numberFormat = NumberFormat.getInstance();
        // 不显示千位分割符,否则显示结果会变成类似1,234,567,890
        numberFormat.setGroupingUsed(false);
        if (cell == null) {
            return "null";
        }
        String value = cell.toString();
        int i = cell.getCellType();
        if (i == 1) {//字符串类型
            return value;
        } else {
            value =numberFormat.format(cell.getNumericCellValue());
            return value;
        }
    }

使用:

output.setVersionNum(Integer.parseInt(this.numberFormat(row.getCell(11))));

原理:先将整数转换成字符串,再将字符串转换成Integer类型


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM