Merge pull request #8463 from wugangca/BAEL-3656

BAEL-3656 Read Numeric Strings in Excel Cells as a String with Apache…
This commit is contained in:
Eric Martin
2020-01-08 21:24:05 -06:00
committed by GitHub
3 changed files with 107 additions and 0 deletions
@@ -0,0 +1,20 @@
package com.baeldung.poi.excel;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Workbook;
public class ExcelCellFormatter {
public String getCellStringValue(Cell cell) {
DataFormatter formatter = new DataFormatter();
return formatter.formatCellValue(cell);
}
public String getCellStringValueWithFormula(Cell cell, Workbook workbook) {
DataFormatter formatter = new DataFormatter();
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
return formatter.formatCellValue(cell, evaluator);
}
}