@@ -162,19 +162,19 @@ public void writeValue(Object val) {
162162 if (val == null ) {
163163 this .cell .setCellValue ("" );
164164 } else if (val instanceof Integer || val instanceof Long ) {
165- this .formatStyle (( short ) 1 );
165+ this .formatStyle ("0" );
166166 this .cell .setCellValue (Integer .parseInt (String .valueOf (val )));
167167 } else if (val instanceof Double ) {
168- this .formatStyle (( short ) 4 );
168+ this .formatStyle ("#0.00" );
169169 this .cell .setCellValue (Double .parseDouble (String .valueOf (val )));
170170 } else if (val instanceof Date ) {
171- this .formatStyle (( short ) 22 );
171+ this .formatStyle ("yyyy-MM-dd HH:mm" );
172172 this .cell .setCellValue ((Date ) val );
173173 } else if (val instanceof LocalDate ) {
174- this .formatStyle (( short ) 14 );
174+ this .formatStyle ("yyyy-MM-dd" );
175175 this .cell .setCellValue ((LocalDate ) val );
176176 } else if (val instanceof LocalDateTime ) {
177- this .formatStyle (( short ) 22 );
177+ this .formatStyle ("yyyy-MM-dd HH:mm" );
178178 this .cell .setCellValue ((LocalDateTime ) val );
179179 } else if (val instanceof Boolean ) {
180180 cell .setCellValue ((Boolean ) val );
@@ -205,4 +205,18 @@ public void formatStyle(short dataFormat) {
205205 newCellStyle .setDataFormat (dataFormat );
206206 this .cell .setCellStyle (newCellStyle );
207207 }
208+
209+ /**
210+ * Format the cell according to the chosen format
211+ * @param dataFormat The string that defines the data format
212+ * @since 0.5.0
213+ */
214+ public void formatStyle (String dataFormat ) {
215+ ExcelWorkbook excelWorkbook = this .getRow ().getSheet ().getWorkbook ();
216+ CreationHelper creationHelper = excelWorkbook .getWorkbook ().getCreationHelper ();
217+ CellStyle newCellStyle = excelWorkbook .getWorkbook ().createCellStyle ();
218+ newCellStyle .cloneStyleFrom (this .cell .getCellStyle ());
219+ newCellStyle .setDataFormat (creationHelper .createDataFormat ().getFormat (dataFormat ));
220+ this .cell .setCellStyle (newCellStyle );
221+ }
208222}
0 commit comments