/**
* 获取单元格的值, 所见即所得(日期未完善)
* @param cell
* @return
*/
public static String getCellValue(Cell cell) {
if(cell == null)
return "";
DataFormatter dataFormatter = new DataFormatter();
String res = null;
if(cell.getCellType() == CellType.FORMULA) {
FormulaEvaluator evaluator = cell.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator();
res = dataFormatter.formatCellValue(cell, evaluator);
} else {
res = dataFormatter.formatCellValue(cell);
}
String dataFormatString = cell.getCellStyle().getDataFormatString();
if (!StringUtil.isNull(dataFormatString)) {
if(dataFormatString.matches("@\".+\"")) {
Pattern p = Pattern.compile("@\"(.+)\"");
Matcher m = p.matcher(dataFormatString);
m.find();
res = res + m.group(1);
}
}
return res;
}
poi excel cell 获取单元格的值
最新推荐文章于 2024-06-26 16:12:50 发布