]> source.dussan.org Git - poi.git/commitdiff
[bug-66365] rework XSSFCell getRichStringCellValue and getStringCellValue to better...
authorPJ Fanning <fanningpj@apache.org>
Mon, 28 Nov 2022 13:05:45 +0000 (13:05 +0000)
committerPJ Fanning <fanningpj@apache.org>
Mon, 28 Nov 2022 13:05:45 +0000 (13:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1905571 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java
poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java
src/resources/ooxml-lite-report.xsb
test-data/spreadsheet/66365.xlsx [new file with mode: 0644]

index bbdb2c35e5658241914a10feaedc71dfd1f21ce2..13c1e7848c19f13df8385ca4a99f6388c2643ff5 100644 (file)
@@ -297,39 +297,14 @@ public final class XSSFCell extends CellBase {
                 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 CellBase {
         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));
index ab606f93dcd4a9cd2450ef4d4b1676fb58e5bf06..ac903cc661c1e0f570933beae39c90acd76cf4a4 100644 (file)
@@ -754,6 +754,17 @@ public final class TestXSSFWorkbook extends BaseTestXWorkbook {
         }
     }
 
+    @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) {
index 252580de10ad6fe932efbd989ab6d39bc3d58e22..352d65040828eae22280d05d87dd4ea45d760b56 100644 (file)
@@ -1168,3 +1168,8 @@ ctshapenonvisual6121type
 ctsdtrow2f71type
 ctsdtcontentrow740etype
 cttableformulaf801type
+sttotalsrowfunctioncb72type
+ctbubblechart3ff4type
+ctbubblesere172type
+ctdlblpos9ce4type
+stdlblpos1cf4type
diff --git a/test-data/spreadsheet/66365.xlsx b/test-data/spreadsheet/66365.xlsx
new file mode 100644 (file)
index 0000000..e308de2
Binary files /dev/null and b/test-data/spreadsheet/66365.xlsx differ