Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

TestXSSFFormulaEvaluation.java 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xssf.usermodel;
  16. import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
  17. import static org.junit.jupiter.api.Assertions.assertEquals;
  18. import static org.junit.jupiter.api.Assertions.assertNotNull;
  19. import static org.junit.jupiter.api.Assertions.assertSame;
  20. import static org.junit.jupiter.api.Assertions.assertThrows;
  21. import java.io.IOException;
  22. import java.math.BigDecimal;
  23. import java.math.MathContext;
  24. import java.math.RoundingMode;
  25. import java.text.DecimalFormat;
  26. import java.util.HashMap;
  27. import java.util.Map;
  28. import java.util.function.Function;
  29. import org.apache.poi.hssf.HSSFTestDataSamples;
  30. import org.apache.poi.ss.usermodel.BaseTestFormulaEvaluator;
  31. import org.apache.poi.ss.usermodel.Cell;
  32. import org.apache.poi.ss.usermodel.CellValue;
  33. import org.apache.poi.ss.usermodel.DataFormatter;
  34. import org.apache.poi.ss.usermodel.FormulaEvaluator;
  35. import org.apache.poi.ss.usermodel.Row;
  36. import org.apache.poi.ss.usermodel.Sheet;
  37. import org.apache.poi.ss.usermodel.Workbook;
  38. import org.apache.poi.ss.util.CellReference;
  39. import org.apache.poi.xssf.XSSFITestDataProvider;
  40. import org.apache.poi.xssf.XSSFTestDataSamples;
  41. import org.junit.jupiter.api.Disabled;
  42. import org.junit.jupiter.api.Test;
  43. import org.junit.jupiter.params.ParameterizedTest;
  44. import org.junit.jupiter.params.provider.ValueSource;
  45. public final class TestXSSFFormulaEvaluation extends BaseTestFormulaEvaluator {
  46. public TestXSSFFormulaEvaluation() {
  47. super(XSSFITestDataProvider.instance);
  48. }
  49. @Test
  50. void testSharedFormulas_evaluateInCell() throws IOException {
  51. try (Workbook wb = _testDataProvider.openSampleWorkbook("49872.xlsx")) {
  52. FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
  53. Sheet sheet = wb.getSheetAt(0);
  54. double result = 3.0;
  55. // B3 is a master shared formula, C3 and D3 don't have the formula written in their f element.
  56. // Instead, the attribute si for a particular cell is used to figure what the formula expression
  57. // should be based on the cell's relative location to the master formula, e.g.
  58. // B3: <f t="shared" ref="B3:D3" si="0">B1+B2</f>
  59. // C3 and D3: <f t="shared" si="0"/>
  60. // get B3 and evaluate it in the cell
  61. Cell b3 = sheet.getRow(2).getCell(1);
  62. assertEquals(result, evaluator.evaluateInCell(b3).getNumericCellValue(), 0);
  63. //at this point the master formula is gone, but we are still able to evaluate dependent cells
  64. Cell c3 = sheet.getRow(2).getCell(2);
  65. assertEquals(result, evaluator.evaluateInCell(c3).getNumericCellValue(), 0);
  66. Cell d3 = sheet.getRow(2).getCell(3);
  67. assertEquals(result, evaluator.evaluateInCell(d3).getNumericCellValue(), 0);
  68. }
  69. }
  70. /**
  71. * Evaluation of cell references with column indexes greater than 255. See bugzilla 50096
  72. */
  73. @Test
  74. void testEvaluateColumnGreaterThan255() throws IOException {
  75. try (Workbook wb = _testDataProvider.openSampleWorkbook("50096.xlsx")) {
  76. FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
  77. /*
  78. * The first row simply contains the numbers 1 - 300.
  79. * The second row simply refers to the cell value above in the first row by a simple formula.
  80. */
  81. for (int i = 245; i < 265; i++) {
  82. Cell cell_noformula = wb.getSheetAt(0).getRow(0).getCell(i);
  83. Cell cell_formula = wb.getSheetAt(0).getRow(1).getCell(i);
  84. CellReference ref_noformula = new CellReference(cell_noformula.getRowIndex(), cell_noformula.getColumnIndex());
  85. CellReference ref_formula = new CellReference(cell_noformula.getRowIndex(), cell_noformula.getColumnIndex());
  86. String fmla = cell_formula.getCellFormula();
  87. // assure that the formula refers to the cell above.
  88. // the check below is 'deep' and involves conversion of the shared formula:
  89. // in the sample file a shared formula in GN1 is spanned in the range GN2:IY2,
  90. assertEquals(ref_noformula.formatAsString(), fmla);
  91. CellValue cv_noformula = evaluator.evaluate(cell_noformula);
  92. CellValue cv_formula = evaluator.evaluate(cell_formula);
  93. assertEquals(cv_noformula.getNumberValue(), cv_formula.getNumberValue(), 0,
  94. "Wrong evaluation result in " + ref_formula.formatAsString());
  95. }
  96. }
  97. }
  98. /**
  99. * Related to bugs #56737 and #56752 - XSSF workbooks which have
  100. * formulas that refer to cells and named ranges in multiple other
  101. * workbooks, both HSSF and XSSF ones
  102. */
  103. @Test
  104. void testReferencesToOtherWorkbooks() throws Exception {
  105. try (Workbook wb = _testDataProvider.openSampleWorkbook("ref2-56737.xlsx")) {
  106. FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
  107. Sheet s = wb.getSheetAt(0);
  108. // References to a .xlsx file
  109. Row rXSLX = s.getRow(2);
  110. Cell cXSLX_cell = rXSLX.getCell(4);
  111. Cell cXSLX_sNR = rXSLX.getCell(6);
  112. Cell cXSLX_gNR = rXSLX.getCell(8);
  113. assertEquals("[1]Uses!$A$1", cXSLX_cell.getCellFormula());
  114. assertEquals("[1]Defines!NR_To_A1", cXSLX_sNR.getCellFormula());
  115. assertEquals("[1]!NR_Global_B2", cXSLX_gNR.getCellFormula());
  116. assertEquals("Hello!", cXSLX_cell.getStringCellValue());
  117. assertEquals("Test A1", cXSLX_sNR.getStringCellValue());
  118. assertEquals(142.0, cXSLX_gNR.getNumericCellValue(), 0);
  119. // References to a .xls file
  120. Row rXSL = s.getRow(4);
  121. Cell cXSL_cell = rXSL.getCell(4);
  122. Cell cXSL_sNR = rXSL.getCell(6);
  123. Cell cXSL_gNR = rXSL.getCell(8);
  124. assertEquals("[2]Uses!$C$1", cXSL_cell.getCellFormula());
  125. assertEquals("[2]Defines!NR_To_A1", cXSL_sNR.getCellFormula());
  126. assertEquals("[2]!NR_Global_B2", cXSL_gNR.getCellFormula());
  127. assertEquals("Hello!", cXSL_cell.getStringCellValue());
  128. assertEquals("Test A1", cXSL_sNR.getStringCellValue());
  129. assertEquals(142.0, cXSL_gNR.getNumericCellValue(), 0);
  130. // Try to evaluate without references, won't work
  131. // (At least, not unit we fix bug #56752 that is)
  132. assertThrows(Exception.class, () -> evaluator.evaluate(cXSL_cell),
  133. "Without a fix for #56752, shouldn't be able to evaluate a reference to a non-provided linked workbook");
  134. // Setup the environment
  135. Map<String, FormulaEvaluator> evaluators = new HashMap<>();
  136. evaluators.put("ref2-56737.xlsx", evaluator);
  137. try (Workbook wbEval1 = _testDataProvider.openSampleWorkbook("56737.xlsx");
  138. Workbook wbEval2 = HSSFTestDataSamples.openSampleWorkbook("56737.xls")) {
  139. evaluators.put("56737.xlsx", wbEval1.getCreationHelper().createFormulaEvaluator());
  140. evaluators.put("56737.xls", wbEval2.getCreationHelper().createFormulaEvaluator());
  141. evaluator.setupReferencedWorkbooks(evaluators);
  142. // Try evaluating all of them, ensure we don't blow up
  143. for (Row r : s) {
  144. for (Cell c : r) {
  145. evaluator.evaluate(c);
  146. }
  147. }
  148. // And evaluate the other way too
  149. evaluator.evaluateAll();
  150. // Static evaluator won't work, as no references passed in
  151. assertThrows(Exception.class, () -> XSSFFormulaEvaluator.evaluateAllFormulaCells(wb),
  152. "Static method lacks references, shouldn't work");
  153. // Evaluate specific cells and check results
  154. assertEquals("\"Hello!\"", evaluator.evaluate(cXSLX_cell).formatAsString());
  155. assertEquals("\"Test A1\"", evaluator.evaluate(cXSLX_sNR).formatAsString());
  156. assertEquals("142.0", evaluator.evaluate(cXSLX_gNR).formatAsString());
  157. assertEquals("\"Hello!\"", evaluator.evaluate(cXSL_cell).formatAsString());
  158. assertEquals("\"Test A1\"", evaluator.evaluate(cXSL_sNR).formatAsString());
  159. assertEquals("142.0", evaluator.evaluate(cXSL_gNR).formatAsString());
  160. // Add another formula referencing these workbooks
  161. Cell cXSL_cell2 = rXSL.createCell(40);
  162. cXSL_cell2.setCellFormula("[56737.xls]Uses!$C$1");
  163. // TODO Shouldn't it become [2] like the others?
  164. assertEquals("[56737.xls]Uses!$C$1", cXSL_cell2.getCellFormula());
  165. assertEquals("\"Hello!\"", evaluator.evaluate(cXSL_cell2).formatAsString());
  166. // Now add a formula that refers to yet another (different) workbook
  167. // Won't work without the workbook being linked
  168. Cell cXSLX_nw_cell = rXSLX.createCell(42);
  169. assertThrows(Exception.class, () -> cXSLX_nw_cell.setCellFormula("[alt.xlsx]Sheet1!$A$1"),
  170. "New workbook not linked, shouldn't be able to add");
  171. }
  172. // Link and re-try
  173. try (Workbook alt = new XSSFWorkbook()) {
  174. alt.createSheet().createRow(0).createCell(0).setCellValue("In another workbook");
  175. // TODO Implement the rest of this, see bug #57184
  176. /*
  177. wb.linkExternalWorkbook("alt.xlsx", alt);
  178. cXSLX_nw_cell.setCellFormula("[alt.xlsx]Sheet1!$A$1");
  179. // Check it - TODO Is this correct? Or should it become [3]Sheet1!$A$1 ?
  180. assertEquals("[alt.xlsx]Sheet1!$A$1", cXSLX_nw_cell.getCellFormula());
  181. // Evaluate it, without a link to that workbook
  182. assertThrows(Exception.class, () -> evaluator.evaluate(cXSLX_nw_cell),
  183. "No cached value and no link to workbook, shouldn't evaluate");
  184. // Add a link, check it does
  185. evaluators.put("alt.xlsx", alt.getCreationHelper().createFormulaEvaluator());
  186. evaluator.setupReferencedWorkbooks(evaluators);
  187. evaluator.evaluate(cXSLX_nw_cell);
  188. assertEquals("In another workbook", cXSLX_nw_cell.getStringCellValue());
  189. */
  190. }
  191. }
  192. }
  193. /*
  194. * If a formula references cells or named ranges in another workbook,
  195. * but that isn't available at evaluation time, the cached values
  196. * should be used instead
  197. * TODO Add the support then add a unit test
  198. * See bug #56752
  199. */
  200. // @Disabled
  201. // void testCachedReferencesToOtherWorkbooks() {
  202. // }
  203. /**
  204. * A handful of functions (such as SUM, COUNTA, MIN) support
  205. * multi-sheet references (eg Sheet1:Sheet3!A1 = Cell A1 from
  206. * Sheets 1 through Sheet 3).
  207. * This test, based on common test files for HSSF and XSSF, checks
  208. * that we can correctly evaluate these
  209. */
  210. @ParameterizedTest
  211. @ValueSource(strings = {"55906-MultiSheetRefs.xls","55906-MultiSheetRefs.xlsx"})
  212. void testMultiSheetReferencesHSSFandXSSF(String sampleFileName) throws Exception {
  213. Function<String, Workbook> fun = sampleFileName.endsWith("x")
  214. ? XSSFTestDataSamples::openSampleWorkbook : HSSFTestDataSamples::openSampleWorkbook;
  215. try (Workbook wb = fun.apply(sampleFileName)) {
  216. FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
  217. Sheet s1 = wb.getSheetAt(0);
  218. // Simple SUM over numbers
  219. Cell sumF = s1.getRow(2).getCell(0);
  220. assertNotNull(sumF);
  221. assertEquals("SUM(Sheet1:Sheet3!A1)", sumF.getCellFormula());
  222. assertEquals("66.0", evaluator.evaluate(sumF).formatAsString(), "Failed for " + wb.getClass());
  223. // Various Stats formulas on numbers
  224. Cell avgF = s1.getRow(2).getCell(1);
  225. assertNotNull(avgF);
  226. assertEquals("AVERAGE(Sheet1:Sheet3!A1)", avgF.getCellFormula());
  227. assertEquals("22.0", evaluator.evaluate(avgF).formatAsString());
  228. Cell minF = s1.getRow(3).getCell(1);
  229. assertNotNull(minF);
  230. assertEquals("MIN(Sheet1:Sheet3!A$1)", minF.getCellFormula());
  231. assertEquals("11.0", evaluator.evaluate(minF).formatAsString());
  232. Cell maxF = s1.getRow(4).getCell(1);
  233. assertNotNull(maxF);
  234. assertEquals("MAX(Sheet1:Sheet3!A$1)", maxF.getCellFormula());
  235. assertEquals("33.0", evaluator.evaluate(maxF).formatAsString());
  236. Cell countF = s1.getRow(5).getCell(1);
  237. assertNotNull(countF);
  238. assertEquals("COUNT(Sheet1:Sheet3!A$1)", countF.getCellFormula());
  239. assertEquals("3.0", evaluator.evaluate(countF).formatAsString());
  240. // Various CountAs on Strings
  241. Cell countA_1F = s1.getRow(2).getCell(2);
  242. assertNotNull(countA_1F);
  243. assertEquals("COUNTA(Sheet1:Sheet3!C1)", countA_1F.getCellFormula());
  244. assertEquals("3.0", evaluator.evaluate(countA_1F).formatAsString());
  245. Cell countA_2F = s1.getRow(2).getCell(3);
  246. assertNotNull(countA_2F);
  247. assertEquals("COUNTA(Sheet1:Sheet3!D1)", countA_2F.getCellFormula());
  248. assertEquals("0.0", evaluator.evaluate(countA_2F).formatAsString());
  249. Cell countA_3F = s1.getRow(2).getCell(4);
  250. assertNotNull(countA_3F);
  251. assertEquals("COUNTA(Sheet1:Sheet3!E1)", countA_3F.getCellFormula());
  252. assertEquals("3.0", evaluator.evaluate(countA_3F).formatAsString());
  253. }
  254. }
  255. /**
  256. * A handful of functions (such as SUM, COUNTA, MIN) support
  257. * multi-sheet areas (eg Sheet1:Sheet3!A1:B2 = Cell A1 to Cell B2,
  258. * from Sheets 1 through Sheet 3).
  259. * This test, based on common test files for HSSF and XSSF, checks
  260. * that we can correctly evaluate these
  261. */
  262. @ParameterizedTest
  263. @ValueSource(strings = {"55906-MultiSheetRefs.xls","55906-MultiSheetRefs.xlsx"})
  264. void testMultiSheetAreasHSSFandXSSF(String sampleFileName) throws Exception {
  265. Function<String, Workbook> fun = sampleFileName.endsWith("x")
  266. ? XSSFTestDataSamples::openSampleWorkbook : HSSFTestDataSamples::openSampleWorkbook;
  267. try (Workbook wb = fun.apply(sampleFileName)) {
  268. FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
  269. Sheet s1 = wb.getSheetAt(0);
  270. // SUM over a range
  271. Cell sumFA = s1.getRow(2).getCell(7);
  272. assertNotNull(sumFA);
  273. assertEquals("SUM(Sheet1:Sheet3!A1:B2)", sumFA.getCellFormula());
  274. assertEquals("110.0", evaluator.evaluate(sumFA).formatAsString(), "Failed for " + wb.getClass());
  275. // Various Stats formulas on ranges of numbers
  276. Cell avgFA = s1.getRow(2).getCell(8);
  277. assertNotNull(avgFA);
  278. assertEquals("AVERAGE(Sheet1:Sheet3!A1:B2)", avgFA.getCellFormula());
  279. assertEquals("27.5", evaluator.evaluate(avgFA).formatAsString());
  280. Cell minFA = s1.getRow(3).getCell(8);
  281. assertNotNull(minFA);
  282. assertEquals("MIN(Sheet1:Sheet3!A$1:B$2)", minFA.getCellFormula());
  283. assertEquals("11.0", evaluator.evaluate(minFA).formatAsString());
  284. Cell maxFA = s1.getRow(4).getCell(8);
  285. assertNotNull(maxFA);
  286. assertEquals("MAX(Sheet1:Sheet3!A$1:B$2)", maxFA.getCellFormula());
  287. assertEquals("44.0", evaluator.evaluate(maxFA).formatAsString());
  288. Cell countFA = s1.getRow(5).getCell(8);
  289. assertNotNull(countFA);
  290. assertEquals("COUNT(Sheet1:Sheet3!$A$1:$B$2)", countFA.getCellFormula());
  291. assertEquals("4.0", evaluator.evaluate(countFA).formatAsString());
  292. }
  293. }
  294. @ParameterizedTest
  295. @ValueSource(strings = {
  296. // bug 57721
  297. "evaluate_formula_with_structured_table_references.xlsx"
  298. // bug 57840:
  299. // Takes over a minute to evaluate all formulas in this large workbook. Run this test when profiling for formula evaluation speed.
  300. // , "StructuredRefs-lots-with-lookups.xlsx"
  301. })
  302. void verifyAllFormulasInWorkbookCanBeEvaluated(String sampleWorkbook) throws IOException {
  303. try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook(sampleWorkbook)) {
  304. assertDoesNotThrow(() -> XSSFFormulaEvaluator.evaluateAllFormulaCells(wb));
  305. }
  306. }
  307. @Test
  308. void test59736() throws IOException {
  309. try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("59736.xlsx")) {
  310. FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
  311. Cell cell = wb.getSheetAt(0).getRow(0).getCell(0);
  312. assertEquals(1, cell.getNumericCellValue(), 0.001);
  313. cell = wb.getSheetAt(0).getRow(1).getCell(0);
  314. CellValue value = evaluator.evaluate(cell);
  315. assertEquals(1, value.getNumberValue(), 0.001);
  316. cell = wb.getSheetAt(0).getRow(2).getCell(0);
  317. value = evaluator.evaluate(cell);
  318. assertEquals(1, value.getNumberValue(), 0.001);
  319. }
  320. }
  321. @Test
  322. void evaluateInCellReturnsSameDataType() throws IOException {
  323. try (XSSFWorkbook wb = new XSSFWorkbook()) {
  324. wb.createSheet().createRow(0).createCell(0);
  325. XSSFFormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
  326. XSSFCell cell = wb.getSheetAt(0).getRow(0).getCell(0);
  327. XSSFCell same = evaluator.evaluateInCell(cell);
  328. assertSame(cell, same);
  329. }
  330. }
  331. @Test
  332. void testBug61468() throws IOException {
  333. try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("simple-monthly-budget.xlsx")) {
  334. FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
  335. Cell cell = wb.getSheetAt(0).getRow(8).getCell(4);
  336. assertEquals(3750, cell.getNumericCellValue(), 0.001);
  337. CellValue value = evaluator.evaluate(cell);
  338. assertEquals(3750, value.getNumberValue(), 0.001);
  339. }
  340. }
  341. @Test
  342. @Disabled("this is from an open bug/discussion over handling localization for number formats")
  343. void testBug61495() throws IOException {
  344. try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("61495-test.xlsm")) {
  345. FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
  346. Cell cell = wb.getSheetAt(0).getRow(0).getCell(1);
  347. // assertEquals("D 67.10", cell.getStringCellValue());
  348. String act = evaluator.evaluate(cell).getStringValue();
  349. assertEquals("D 67.10", act);
  350. cell = wb.getSheetAt(0).getRow(1).getCell(1);
  351. act = evaluator.evaluate(cell).getStringValue();
  352. assertEquals("D 0,068", act);
  353. }
  354. }
  355. /**
  356. * see bug 62834, handle when a shared formula range doesn't contain only formula cells
  357. */
  358. @Test
  359. void testBug62834() throws IOException {
  360. try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("62834.xlsx")) {
  361. FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
  362. Cell a2 = wb.getSheetAt(0).getRow(1).getCell(0);
  363. Cell value = evaluator.evaluateInCell(a2);
  364. assertEquals("a value", value.getStringCellValue(), "wrong value A2");
  365. // evaluator.clearAllCachedResultValues();
  366. Cell a3 = wb.getSheetAt(0).getRow(2).getCell(0);
  367. value = evaluator.evaluateInCell(a3);
  368. assertEquals("a value", value.getStringCellValue(), "wrong value A3");
  369. Cell a5 = wb.getSheetAt(0).getRow(4).getCell(0);
  370. value = evaluator.evaluateInCell(a5);
  371. assertEquals("another value", value.getStringCellValue(), "wrong value A5");
  372. }
  373. }
  374. @Test
  375. void testBug63934() throws IOException {
  376. try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("63934.xlsx")) {
  377. final Cell cell = wb.getSheetAt(0).getRow(1).getCell(1);
  378. assertNotNull(cell);
  379. final FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
  380. final CellValue value = evaluator.evaluate(cell);
  381. assertEquals("Male", value.getStringValue());
  382. }
  383. }
  384. }