File tree Expand file tree Collapse file tree 3 files changed +29
-2
lines changed
main/java/com/monitorjbl/xlsx/impl Expand file tree Collapse file tree 3 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -189,7 +189,9 @@ && isSpreadsheetTag(event.asStartElement().getName())) {
189189 }
190190 }
191191 } else if ("f" .equals (tagLocalName )) {
192- currentCell .setType ("str" );
192+ if (currentCell != null ) {
193+ currentCell .setType ("str" );
194+ }
193195 }
194196
195197 // Clear contents cache
@@ -207,9 +209,12 @@ && isSpreadsheetTag(event.asEndElement().getName())) {
207209 currentRowNum ++;
208210 } else if ("c" .equals (tagLocalName )) {
209211 currentRow .getCellMap ().put (currentCell .getColumnIndex (), currentCell );
212+ currentCell = null ;
210213 currentColNum ++;
211214 } else if ("f" .equals (tagLocalName )) {
212- currentCell .setFormula (lastContents );
215+ if (currentCell != null ) {
216+ currentCell .setFormula (lastContents );
217+ }
213218 }
214219
215220 }
Original file line number Diff line number Diff line change 44import org .apache .poi .openxml4j .opc .OPCPackage ;
55import org .apache .poi .openxml4j .opc .PackageAccess ;
66import org .apache .poi .ss .usermodel .Cell ;
7+ import org .apache .poi .ss .usermodel .CellType ;
78import org .apache .poi .ss .usermodel .DateUtil ;
89import org .apache .poi .ss .usermodel .Row ;
910import org .apache .poi .ss .usermodel .Workbook ;
@@ -671,4 +672,25 @@ public void testShouldHandleBlankSSTReference() throws Exception {
671672 }
672673 }
673674 }
675+
676+ // The last cell on this sheet should be a NUMERIC but there is a lingering "f"
677+ // tag that was getting attached to the last cell causing it to be a FORUMLA.
678+ @ Test
679+ public void testForumulaOutsideCellIgnored () throws Exception {
680+ try (
681+ InputStream is = new FileInputStream (new File ("src/test/resources/formula_outside_cell.xlsx" ));
682+ Workbook wb = StreamingReader .builder ().open (is );
683+ ) {
684+ Iterator <Row > rows = wb .getSheetAt (0 ).iterator ();
685+ Cell cell = null ;
686+ while (rows .hasNext ()) {
687+ Iterator <Cell > cells = rows .next ().iterator ();
688+ while (cells .hasNext ()) {
689+ cell = cells .next ();
690+ }
691+ }
692+ assertNotNull (cell );
693+ assertThat (cell .getCellTypeEnum (), is (CellType .NUMERIC ));
694+ }
695+ }
674696}
You can’t perform that action at this time.
0 commit comments