Commit cf4d5b42 by 张祺

增加格式化数据限制

parent 0010162c
...@@ -3,11 +3,21 @@ package com.keymobile.indicators.utils; ...@@ -3,11 +3,21 @@ package com.keymobile.indicators.utils;
import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFCell;
import java.math.RoundingMode;
import java.text.NumberFormat;
/** /**
* excel操作工具类 * excel操作工具类
*/ */
public class ExcelUtil { public class ExcelUtil {
private static NumberFormat numberFormat = NumberFormat.getNumberInstance();
static {
numberFormat.setRoundingMode(RoundingMode.HALF_UP);
numberFormat.setGroupingUsed(false);
}
/** /**
* 获取excel单元格值 * 获取excel单元格值
* @param xssfCell * @param xssfCell
...@@ -20,7 +30,8 @@ public class ExcelUtil { ...@@ -20,7 +30,8 @@ public class ExcelUtil {
if (CellType.STRING.equals(cellType)) { if (CellType.STRING.equals(cellType)) {
cellValue = xssfCell.getStringCellValue(); cellValue = xssfCell.getStringCellValue();
} else if (CellType.NUMERIC.equals(cellType)) { } else if (CellType.NUMERIC.equals(cellType)) {
cellValue = String.valueOf(xssfCell.getNumericCellValue()); double d = xssfCell.getNumericCellValue();
cellValue = String.valueOf(numberFormat.format(d));
} else if (CellType.BOOLEAN.equals(cellType)) { } else if (CellType.BOOLEAN.equals(cellType)) {
cellValue = String.valueOf(xssfCell.getBooleanCellValue()); cellValue = String.valueOf(xssfCell.getBooleanCellValue());
} else if (CellType.FORMULA.equals(cellType)) { } else if (CellType.FORMULA.equals(cellType)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment