方法:
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類型