]> source.dussan.org Git - poi.git/commitdiff
fix TextJoin use case that was not handled
authorPJ Fanning <fanningpj@apache.org>
Sat, 7 Aug 2021 11:52:35 +0000 (11:52 +0000)
committerPJ Fanning <fanningpj@apache.org>
Sat, 7 Aug 2021 11:52:35 +0000 (11:52 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1892070 13f79535-47bb-0310-9956-ffa450edef68

poi/src/main/java/org/apache/poi/ss/formula/atp/TextJoinFunction.java
poi/src/test/java/org/apache/poi/ss/formula/atp/TestTextJoinFunction.java

index 8cd588715a5711afc2459fa5dcb92e317d4ab431..85a527261fa448cf160c271b19d0522113095dd8 100644 (file)
@@ -96,14 +96,14 @@ final class TextJoinFunction implements FreeRefFunction {
             if (delimiterArgs.size() == 0) {
                 return new StringEval(String.join("", textValues));
             } else if (delimiterArgs.size() == 1) {
-                String delimiter = OperandResolver.coerceValueToString(delimiterArgs.get(0));
+                String delimiter = coerceValueToString(delimiterArgs.get(0));
                 return new StringEval(String.join(delimiter, textValues));
             } else {
                 //https://support.microsoft.com/en-us/office/textjoin-function-357b449a-ec91-49d0-80c3-0e8fc845691c
                 //see example 3 to see why this is needed
                 List<String> delimiters = new ArrayList<>();
                 for (ValueEval delimiterArg: delimiterArgs) {
-                    delimiters.add(OperandResolver.coerceValueToString(delimiterArg));
+                    delimiters.add(coerceValueToString(delimiterArg));
                 }
                 StringBuilder sb = new StringBuilder();
                 for (int i = 0; i < textValues.size(); i++) {
@@ -120,6 +120,10 @@ final class TextJoinFunction implements FreeRefFunction {
         }
     }
 
+    private String coerceValueToString(ValueEval eval) {
+        return  (eval instanceof MissingArgEval) ? "" : OperandResolver.coerceValueToString(eval);
+    }
+
     //https://support.microsoft.com/en-us/office/textjoin-function-357b449a-ec91-49d0-80c3-0e8fc845691c
     //in example 3, the delimiter is defined by a large area but only the last row of that area seems to be used
     //this is why lastRowOnly is supported
index 6ece0eae7178a1bd75dd2f49554c6648a727aa30..8e8c15a69fcbf61a7ce1b0e6bcb52a5869c8f06c 100644 (file)
@@ -201,6 +201,8 @@ public class TestTextJoinFunction {
             HSSFCell cell = wb.getSheetAt(0).getRow(0).createCell(100);
             confirmResult(fe, cell, "TEXTJOIN(A8:D8, TRUE, A2:D7)",
                     "Tulsa,OK,74133,US;Seattle,WA,98109,US;Iselin,NJ,08830,US;Fort Lauderdale,FL,33309,US;Tempe,AZ,85285,US;end");
+            confirmResult(fe, cell, "TEXTJOIN(, TRUE, A2:D7)",
+                    "TulsaOK74133USSeattleWA98109USIselinNJ08830USFort LauderdaleFL33309USTempeAZ85285USend");
         }
     }