解決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