View | Details | Raw Unified | Return to bug 66365
Collapse All | Expand All

(-)a/poi-ooxml/src/test/java/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java (+11 lines)
Lines 754-759 Link Here
754
        }
754
        }
755
    }
755
    }
756
756
757
    @Test
758
    void bug66365() throws Exception {
759
        try (XSSFWorkbook wb = openSampleWorkbook("66365.xlsx")) {
760
            XSSFSheet sheet1 = wb.getSheetAt(0);
761
            assertEquals(sheet1.getRow(0).getCell(0).getStringCellValue(),
762
                  sheet1.getRow(0).getCell(1).getStringCellValue());
763
            assertEquals(sheet1.getRow(1).getCell(0).getStringCellValue(),
764
                  sheet1.getRow(1).getCell(1).getStringCellValue());
765
        }
766
    }
767
757
    private static final int INDEX_NOT_FOUND = -1;
768
    private static final int INDEX_NOT_FOUND = -1;
758
769
759
    private static boolean isEmpty(CharSequence cs) {
770
    private static boolean isEmpty(CharSequence cs) {
(-)a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFCell.java (-37 / +43 lines)
Lines 297-341 Link Here
297
                rt = new XSSFRichTextString("");
297
                rt = new XSSFRichTextString("");
298
                break;
298
                break;
299
            case STRING:
299
            case STRING:
300
                STCellType.Enum xmlbeanCellType = _cell.getT();
300
                rt = findStringValue();
301
                if (xmlbeanCellType == STCellType.INLINE_STR) {
301
                break;
302
                    if(_cell.isSetIs()) {
302
            case FORMULA: {
303
                        //string is expressed directly in the cell definition instead of implementing the shared string table.
303
                CellType cachedValueType = getBaseCellType(false);
304
                        rt = new XSSFRichTextString(_cell.getIs());
304
                if (cachedValueType != CellType.STRING) {
305
                    } else if (_cell.isSetV()) {
305
                    throw typeMismatch(CellType.STRING, cachedValueType, true);
306
                        //cached result of a formula
306
                }
307
                        rt = new XSSFRichTextString(_cell.getV());
307
                rt = findStringValue();
308
                    } else {
308
                break;
309
                        rt = new XSSFRichTextString("");
309
            }
310
                    }
310
            default:
311
                } else if (xmlbeanCellType == STCellType.STR) {
311
                throw typeMismatch(CellType.STRING, cellType, false);
312
                    //cached formula value
312
        }
313
                    rt = new XSSFRichTextString(_cell.isSetV() ? _cell.getV() : "");
313
        rt.setStylesTableReference(_stylesSource);
314
                } else {
314
        return rt;
315
                    if (_cell.isSetV()) {
315
    }
316
                        try {
316
317
                            int idx = Integer.parseInt(_cell.getV());
317
    private XSSFRichTextString findStringValue() {
318
                            rt = (XSSFRichTextString)_sharedStringSource.getItemAt(idx);
318
        XSSFRichTextString rt;
319
                        } catch(Throwable t) {
319
        STCellType.Enum xmlbeanCellType = _cell.getT();
320
                            rt = new XSSFRichTextString("");
320
        if (xmlbeanCellType == STCellType.INLINE_STR) {
321
                        }
321
            if(_cell.isSetIs()) {
322
                    } else {
322
                //string is expressed directly in the cell definition instead of implementing the shared string table.
323
                        rt = new XSSFRichTextString("");
323
                rt = new XSSFRichTextString(_cell.getIs());
324
                    }
324
            } else if (_cell.isSetV()) {
325
                }
325
                //cached result of a formula
326
                break;
326
                rt = new XSSFRichTextString(_cell.getV());
327
            case FORMULA: {
327
            } else {
328
                CellType cachedValueType = getBaseCellType(false);
328
                rt = new XSSFRichTextString("");
329
                if (cachedValueType != CellType.STRING) {
329
            }
330
                    throw typeMismatch(CellType.STRING, cachedValueType, true);
330
        } else if (xmlbeanCellType == STCellType.STR) {
331
                }
331
            //cached formula value
332
                rt = new XSSFRichTextString(_cell.isSetV() ? _cell.getV() : "");
332
            rt = new XSSFRichTextString(_cell.isSetV() ? _cell.getV() : "");
333
                break;
333
        } else {
334
            if (_cell.isSetV()) {
335
                try {
336
                    int idx = Integer.parseInt(_cell.getV());
337
                    rt = (XSSFRichTextString)_sharedStringSource.getItemAt(idx);
338
                } catch(Throwable t) {
339
                    rt = new XSSFRichTextString("");
340
                }
341
            } else {
342
                rt = new XSSFRichTextString("");
334
            }
343
            }
335
            default:
336
                throw typeMismatch(CellType.STRING, cellType, false);
337
        }
344
        }
338
        rt.setStylesTableReference(_stylesSource);
339
        return rt;
345
        return rt;
340
    }
346
    }
341
347

Return to bug 66365