Created
May 9, 2020 19:29
-
-
Save HashRaygoza/d81635c842e58307ffd1b500430484b4 to your computer and use it in GitHub Desktop.
Agrega datos a un celda de Excel, usando la conversion de tipo adecuada
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protected void agregarDato(Cell celda, Object dato) { | |
| if (dato instanceof BigDecimal) { | |
| BigDecimal d = (BigDecimal) dato; | |
| celda.setCellValue(d.doubleValue()); | |
| } | |
| if (dato instanceof Integer) { | |
| Integer i = (Integer) dato; | |
| celda.setCellValue(i); | |
| } | |
| if (dato instanceof String) { | |
| String i = (String) dato; | |
| celda.setCellValue(i); | |
| } | |
| if (dato instanceof Date) { | |
| CellStyle cellStyle = libro.createCellStyle(); | |
| CreationHelper createHelper = libro.getCreationHelper(); | |
| cellStyle.setDataFormat(createHelper.createDataFormat().getFormat("m/d/yy")); | |
| Date i = (Date) dato; | |
| celda.setCellValue(i); | |
| celda.setCellStyle(cellStyle); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment