Java对excel表格操作一文大致讲解如何上传等
这次主要讲一个问题 就是我们在做excel上传的时候,有时候单元格填写的是一串长数字,在上传中,长度大于11位的数字怎会变成科学计数法,这显然不适合我们的上传。本文就介绍两种方法解决。
方法一:BigDecimal
Cell cell = Row.getCell(index);//取出cellString value = cell.toString;//cell内容BigDecimal bigDecimal = new BigDecimal(value);//创建BigDecimal对象,把科学计数转成数字String res = bigDecimal.toPlainString();//转成最终要的数字字符串
方法二:DecimalFormat
DecimalFormat decimalFormat = new DecimalFormat("0");if (cell.getCellStyle().getDataFormatString().equals("General")){value= decimalFormat.format(cell.getNumericCellValue());}