Author: fanningpj
Date: Mon Nov 28 13:05:45 2022
New Revision: 1905571

URL: http://svn.apache.org/viewvc?rev=1905571&view=rev
Log:
[bug-66365] rework XSSFCell getRichStringCellValue and getStringCellValue to 
better support array formula results. Thanks to Espen Amble Kolstad.

Added:
    poi/trunk/test-data/spreadsheet/66365.xlsx
Modified:
    
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java
    
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
    poi/trunk/src/resources/ooxml-lite-report.xsb

Modified: 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java?rev=1905571&r1=1905570&r2=1905571&view=diff
==============================================================================
--- 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java 
(original)
+++ 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java 
Mon Nov 28 13:05:45 2022
@@ -297,39 +297,14 @@ public final class XSSFCell extends Cell
                 rt = new XSSFRichTextString("");
                 break;
             case STRING:
-                STCellType.Enum xmlbeanCellType = _cell.getT();
-                if (xmlbeanCellType == STCellType.INLINE_STR) {
-                    if(_cell.isSetIs()) {
-                        //string is expressed directly in the cell definition 
instead of implementing the shared string table.
-                        rt = new XSSFRichTextString(_cell.getIs());
-                    } else if (_cell.isSetV()) {
-                        //cached result of a formula
-                        rt = new XSSFRichTextString(_cell.getV());
-                    } else {
-                        rt = new XSSFRichTextString("");
-                    }
-                } else if (xmlbeanCellType == STCellType.STR) {
-                    //cached formula value
-                    rt = new XSSFRichTextString(_cell.isSetV() ? _cell.getV() 
: "");
-                } else {
-                    if (_cell.isSetV()) {
-                        try {
-                            int idx = Integer.parseInt(_cell.getV());
-                            rt = 
(XSSFRichTextString)_sharedStringSource.getItemAt(idx);
-                        } catch(Throwable t) {
-                            rt = new XSSFRichTextString("");
-                        }
-                    } else {
-                        rt = new XSSFRichTextString("");
-                    }
-                }
+                rt = findStringValue();
                 break;
             case FORMULA: {
                 CellType cachedValueType = getBaseCellType(false);
                 if (cachedValueType != CellType.STRING) {
                     throw typeMismatch(CellType.STRING, cachedValueType, true);
                 }
-                rt = new XSSFRichTextString(_cell.isSetV() ? _cell.getV() : 
"");
+                rt = findStringValue();
                 break;
             }
             default:
@@ -339,6 +314,37 @@ public final class XSSFCell extends Cell
         return rt;
     }
 
+    private XSSFRichTextString findStringValue() {
+        XSSFRichTextString rt;
+        STCellType.Enum xmlbeanCellType = _cell.getT();
+        if (xmlbeanCellType == STCellType.INLINE_STR) {
+            if(_cell.isSetIs()) {
+                //string is expressed directly in the cell definition instead 
of implementing the shared string table.
+                rt = new XSSFRichTextString(_cell.getIs());
+            } else if (_cell.isSetV()) {
+                //cached result of a formula
+                rt = new XSSFRichTextString(_cell.getV());
+            } else {
+                rt = new XSSFRichTextString("");
+            }
+        } else if (xmlbeanCellType == STCellType.STR) {
+            //cached formula value
+            rt = new XSSFRichTextString(_cell.isSetV() ? _cell.getV() : "");
+        } else {
+            if (_cell.isSetV()) {
+                try {
+                    int idx = Integer.parseInt(_cell.getV());
+                    rt = 
(XSSFRichTextString)_sharedStringSource.getItemAt(idx);
+                } catch(Throwable t) {
+                    rt = new XSSFRichTextString("");
+                }
+            } else {
+                rt = new XSSFRichTextString("");
+            }
+        }
+        return rt;
+    }
+
     @Override
     protected void setCellValueImpl(String value) {
         setCellValueImpl(new XSSFRichTextString(value));

Modified: 
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java?rev=1905571&r1=1905570&r2=1905571&view=diff
==============================================================================
--- 
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
 (original)
+++ 
poi/trunk/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
 Mon Nov 28 13:05:45 2022
@@ -754,6 +754,17 @@ public final class TestXSSFWorkbook exte
         }
     }
 
+    @Test
+    void bug66365() throws Exception {
+        try (XSSFWorkbook wb = openSampleWorkbook("66365.xlsx")) {
+            XSSFSheet sheet1 = wb.getSheetAt(0);
+            assertEquals(sheet1.getRow(0).getCell(0).getStringCellValue(),
+                  sheet1.getRow(0).getCell(1).getStringCellValue());
+            assertEquals(sheet1.getRow(1).getCell(0).getStringCellValue(),
+                  sheet1.getRow(1).getCell(1).getStringCellValue());
+        }
+    }
+
     private static final int INDEX_NOT_FOUND = -1;
 
     private static boolean isEmpty(CharSequence cs) {

Modified: poi/trunk/src/resources/ooxml-lite-report.xsb
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/resources/ooxml-lite-report.xsb?rev=1905571&r1=1905570&r2=1905571&view=diff
==============================================================================
--- poi/trunk/src/resources/ooxml-lite-report.xsb (original)
+++ poi/trunk/src/resources/ooxml-lite-report.xsb Mon Nov 28 13:05:45 2022
@@ -1168,3 +1168,8 @@ ctshapenonvisual6121type
 ctsdtrow2f71type
 ctsdtcontentrow740etype
 cttableformulaf801type
+sttotalsrowfunctioncb72type
+ctbubblechart3ff4type
+ctbubblesere172type
+ctdlblpos9ce4type
+stdlblpos1cf4type

Added: poi/trunk/test-data/spreadsheet/66365.xlsx
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/66365.xlsx?rev=1905571&view=auto
==============================================================================
Binary files poi/trunk/test-data/spreadsheet/66365.xlsx (added) and 
poi/trunk/test-data/spreadsheet/66365.xlsx Mon Nov 28 13:05:45 2022 differ



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to