1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > poi 不自动计算 设置单元格公式_使用POI读取由excel公式生成单元格数据

poi 不自动计算 设置单元格公式_使用POI读取由excel公式生成单元格数据

时间:2018-07-14 07:00:32

相关推荐

poi 不自动计算 设置单元格公式_使用POI读取由excel公式生成单元格数据

需求:读取这里面的数字3

实现:

public String getCellValue(HSSFCell cell) {

String value = null;

if (cell != null) {

switch (cell.getCellType()) {

case HSSFCell.CELL_TYPE_FORMULA:

// cell.getCellFormula();

try {

value = String.valueOf(cell.getNumericCellValue());

} catch (IllegalStateException e) {

value = String.valueOf(cell.getRichStringCellValue());

}

break;

case HSSFCell.CELL_TYPE_NUMERIC:

value = String.valueOf(cell.getNumericCellValue());

break;

case HSSFCell.CELL_TYPE_STRING:

value = String.valueOf(cell.getRichStringCellValue());

break;

}

}

return switchNumeric(value);

}

public static String switchNumeric(String str){

if(str.indexOf(".")>0){

str = str.replaceAll("0+?$", "").replaceAll("[.]$", "");;

}

return str;

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。