File tree 3 files changed +29
-2
lines changed
main/java/com/monitorjbl/xlsx/impl
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())) {
189
189
}
190
190
}
191
191
} else if ("f" .equals (tagLocalName )) {
192
- currentCell .setType ("str" );
192
+ if (currentCell != null ) {
193
+ currentCell .setType ("str" );
194
+ }
193
195
}
194
196
195
197
// Clear contents cache
@@ -207,9 +209,12 @@ && isSpreadsheetTag(event.asEndElement().getName())) {
207
209
currentRowNum ++;
208
210
} else if ("c" .equals (tagLocalName )) {
209
211
currentRow .getCellMap ().put (currentCell .getColumnIndex (), currentCell );
212
+ currentCell = null ;
210
213
currentColNum ++;
211
214
} else if ("f" .equals (tagLocalName )) {
212
- currentCell .setFormula (lastContents );
215
+ if (currentCell != null ) {
216
+ currentCell .setFormula (lastContents );
217
+ }
213
218
}
214
219
215
220
}
Original file line number Diff line number Diff line change 4
4
import org .apache .poi .openxml4j .opc .OPCPackage ;
5
5
import org .apache .poi .openxml4j .opc .PackageAccess ;
6
6
import org .apache .poi .ss .usermodel .Cell ;
7
+ import org .apache .poi .ss .usermodel .CellType ;
7
8
import org .apache .poi .ss .usermodel .DateUtil ;
8
9
import org .apache .poi .ss .usermodel .Row ;
9
10
import org .apache .poi .ss .usermodel .Workbook ;
@@ -671,4 +672,25 @@ public void testShouldHandleBlankSSTReference() throws Exception {
671
672
}
672
673
}
673
674
}
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
+ }
674
696
}
You can’t perform that action at this time.
0 commit comments