diff --git a/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionEval.java b/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionEval.java index 5e00aaff03..c544d4680a 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionEval.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/eval/FunctionEval.java @@ -292,7 +292,7 @@ public final class FunctionEval { // 309: FORECAST // 310: FTEST retval[311] = new Intercept(); - // 312: PEARSON + retval[312] = Correl.instance; // 313: RSQ // 314: STEYX retval[315] = new Slope(); diff --git a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestCorrel.java b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestCorrel.java index 384cbdf561..3be25d2c23 100644 --- a/poi/src/test/java/org/apache/poi/ss/formula/functions/TestCorrel.java +++ b/poi/src/test/java/org/apache/poi/ss/formula/functions/TestCorrel.java @@ -48,6 +48,18 @@ final class TestCorrel { } } + //https://support.microsoft.com/en-us/office/pearson-function-0c3e30fc-e5af-49c4-808a-3ef66e034c18 + @Test + void testPearsonExample1() throws IOException { + try (HSSFWorkbook wb = initWorkbook2()) { + HSSFSheet sheet = wb.getSheetAt(0); + HSSFRow row = sheet.getRow(0); + HSSFCell cell = row.createCell(100); + HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); + assertDouble(fe, cell, "CORREL(A2:A6,B2:B6)", 0.699379, 0.0000005); + assertDouble(fe, cell, "PEARSON(A2:A6,B2:B6)", 0.699379, 0.0000005); + } + } @Test void testBlankValue() throws IOException { try (HSSFWorkbook wb = initWorkbook1(null)) { @@ -97,4 +109,16 @@ final class TestCorrel { addRow(sheet, 5, 6, 17); return wb; } + + private HSSFWorkbook initWorkbook2() { + HSSFWorkbook wb = new HSSFWorkbook(); + HSSFSheet sheet = wb.createSheet(); + addRow(sheet, 0, "Independent values", "Dependent values"); + addRow(sheet, 1, 9, 10); + addRow(sheet, 2, 7, 6); + addRow(sheet, 3, 5, 1); + addRow(sheet, 4, 3, 5); + addRow(sheet, 5, 1, 3); + return wb; + } }