Add a unit-test to verify that DataFormatter.formatCellValue() does format formula-results correctly
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1751400 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3ef17caad7
commit
6784574ea2
@ -32,10 +32,12 @@ import java.util.Calendar;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.hssf.usermodel.TestHSSFDataFormatter;
|
import org.apache.poi.hssf.usermodel.TestHSSFDataFormatter;
|
||||||
import org.apache.poi.ss.format.CellFormat;
|
import org.apache.poi.ss.format.CellFormat;
|
||||||
import org.apache.poi.ss.format.CellFormatResult;
|
import org.apache.poi.ss.format.CellFormatResult;
|
||||||
|
import org.apache.poi.ss.util.CellReference;
|
||||||
import org.apache.poi.ss.util.NumberToTextConverter;
|
import org.apache.poi.ss.util.NumberToTextConverter;
|
||||||
import org.apache.poi.util.LocaleUtil;
|
import org.apache.poi.util.LocaleUtil;
|
||||||
import org.apache.poi.util.SuppressForbidden;
|
import org.apache.poi.util.SuppressForbidden;
|
||||||
@ -775,4 +777,22 @@ public class TestDataFormatter {
|
|||||||
wb.close();
|
wb.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFormulaEvaluation() throws IOException {
|
||||||
|
Workbook wb = HSSFTestDataSamples.openSampleWorkbook("FormulaEvalTestData.xls");
|
||||||
|
|
||||||
|
CellReference ref = new CellReference("D47");
|
||||||
|
|
||||||
|
Cell cell = wb.getSheetAt(0).getRow(ref.getRow()).getCell(ref.getCol());
|
||||||
|
//noinspection deprecation
|
||||||
|
assertEquals(CellType.FORMULA, cell.getCellTypeEnum());
|
||||||
|
assertEquals("G9:K9 I7:I12", cell.getCellFormula());
|
||||||
|
|
||||||
|
DataFormatter formatter = new DataFormatter();
|
||||||
|
FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
|
||||||
|
assertEquals("5.6789", formatter.formatCellValue(cell, evaluator));
|
||||||
|
|
||||||
|
wb.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user