Created
          August 4, 2020 15:47 
        
      - 
      
- 
        Save HashRaygoza/aa16cc711e6a9977549d6ce20ac8aff6 to your computer and use it in GitHub Desktop. 
  
    
      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
    
  
  
    
  | public class ProcesoReporte extends SwingWorker<Void, Void>{ | |
| public ProcesoReporte() { | |
| this.setProgress(0); | |
| } | |
| private int calcularAvance(int cantidadRegistros, int posicion) { | |
| Double indice = Double.valueOf(posicion); | |
| Double total = Double.valueOf(cantidadRegistros - 1); | |
| double avance = (indice / total) * 100.0; | |
| int progreso = (int) Math.round(avance); | |
| return progreso; | |
| } | |
| public void generarExcel() throws FileNotFoundException, IOException { | |
| XSSFWorkbook libro = new XSSFWorkbook(); | |
| XSSFSheet pagina = libro.createSheet("Pagina"); | |
| GeneradorDatos generadorDatos = new GeneradorDatos(); | |
| ArrayList<Double> datos = generadorDatos.datos(); | |
| this.setProgress(0); | |
| for(int i=0; i< datos.size(); i++){ | |
| Row fila = pagina.createRow(i); | |
| Cell celda = fila.createCell(0); | |
| celda.setCellValue( datos.get(i)); | |
| int progreso = this.calcularAvance(datos.size(), i); | |
| 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.setProgress(0); | |
| this.generarExcel(); | |
| return null; | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment