Skip to content

Instantly share code, notes, and snippets.

@HashRaygoza
Created August 4, 2020 15:41
Show Gist options
  • Save HashRaygoza/2408dcd9932228c4639a6c5dfa1ed8e8 to your computer and use it in GitHub Desktop.
Save HashRaygoza/2408dcd9932228c4639a6c5dfa1ed8e8 to your computer and use it in GitHub Desktop.
public class ProcesoReporte extends SwingWorker<Void, Void>{
public ProcesoReporte() {
this.setProgress(0);
}
public void generarExcel() throws FileNotFoundException, IOException {
XSSFWorkbook libro = new XSSFWorkbook();
XSSFSheet pagina = libro.createSheet("Pagina");
GeneradorDatos generadorDatos = new GeneradorDatos();
ArrayList<Double> datos = generadorDatos.datos();
for(int i=0; i< datos.size(); i++){
Row fila = pagina.createRow(i);
Cell celda = fila.createCell(0);
celda.setCellValue( datos.get(i));
Double indice = Double.valueOf(i);
Double total = Double.valueOf( datos.size() -1 );
System.out.println(indice / total);
double avance = (indice / total) * 100.0;
int progreso = (int) Math.round(avance);
System.out.println("Progreso " + progreso);
this.setProgress(progreso);
System.out.println("Agregando elemento " + i);
}
try (FileOutputStream salida = new FileOutputStream(new File("eventoExcel.xlsx"))) {
libro.write(salida);
}
}
@Override
protected Void doInBackground() throws Exception {
this.generarExcel();
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment