File tree Expand file tree Collapse file tree
main/java/com/monitorjbl/xlsx
test/java/com/monitorjbl/xlsx Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -129,6 +129,18 @@ private void handleEvent(XMLEvent event) throws SAXException {
129129 } else {
130130 currentCell .setType ("n" );
131131 }
132+
133+ Attribute style = startElement .getAttributeByName (new QName ("s" ));
134+
135+ if (style != null ){
136+ String indexStr = style .getValue ();
137+ try {
138+ int index = Integer .parseInt (indexStr );
139+ currentCell .setCellStyle (stylesTable .getStyleAt (index ));
140+ } catch (NumberFormatException nfe ) {
141+ log .warn ("Ignoring invalid style index {}" , indexStr );
142+ }
143+ }
132144 }
133145
134146 // Clear contents cache
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ public class StreamingCell implements Cell {
2525 private Short numericFormatIndex ;
2626 private String type ;
2727 private Row row ;
28+ private CellStyle cellStyle ;
2829
2930 public StreamingCell (int columnIndex , int rowIndex ) {
3031 this .columnIndex = columnIndex ;
@@ -75,6 +76,11 @@ public void setRow(Row row) {
7576 this .row = row ;
7677 }
7778
79+ @ Override
80+ public void setCellStyle (CellStyle cellStyle ) {
81+ this .cellStyle = cellStyle ;
82+ }
83+
7884 /* Supported */
7985
8086 /**
@@ -176,6 +182,17 @@ public Date getDateCellValue() {
176182 return rawContents == null ? null : HSSFDateUtil .getJavaDate (getNumericCellValue ());
177183 }
178184
185+ /**
186+ * Returns the style of the cell
187+ *
188+ * @return the style of the cell
189+ */
190+ @ Override
191+ public CellStyle getCellStyle () {
192+ return this .cellStyle ;
193+ }
194+
195+
179196 /* Not supported */
180197
181198 /**
@@ -298,22 +315,6 @@ public byte getErrorCellValue() {
298315 throw new NotSupportedException ();
299316 }
300317
301- /**
302- * Not supported
303- */
304- @ Override
305- public void setCellStyle (CellStyle style ) {
306- throw new NotSupportedException ();
307- }
308-
309- /**
310- * Not supported
311- */
312- @ Override
313- public CellStyle getCellStyle () {
314- throw new NotSupportedException ();
315- }
316-
317318 /**
318319 * Not supported
319320 */
Original file line number Diff line number Diff line change 22
33import com .monitorjbl .xlsx .exceptions .MissingSheetException ;
44import org .apache .poi .ss .usermodel .Cell ;
5+ import org .apache .poi .ss .usermodel .DateUtil ;
56import org .apache .poi .ss .usermodel .Row ;
67import org .junit .BeforeClass ;
78import org .junit .Test ;
@@ -86,6 +87,7 @@ public void testTypes() throws Exception {
8687 assertEquals (Cell .CELL_TYPE_NUMERIC , row .get (1 ).getCellType ());
8788 assertEquals ("date" , row .get (0 ).getStringCellValue ());
8889 assertEquals (df .parse ("1/1/2014" ), row .get (1 ).getDateCellValue ());
90+ assertTrue (DateUtil .isCellDateFormatted (row .get (1 )));
8991
9092 row = obj .get (5 );
9193 assertEquals (7 , row .size ());
You can’t perform that action at this time.
0 commit comments