Skip to content

Instantly share code, notes, and snippets.

@HashRaygoza
Created May 9, 2020 19:29
Show Gist options
  • Select an option

  • Save HashRaygoza/d81635c842e58307ffd1b500430484b4 to your computer and use it in GitHub Desktop.

Select an option

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
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