Created
August 4, 2020 15:46
-
-
Save HashRaygoza/f1e3b014230c63ae82bddec90518263c 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 EventoOperacionLenta implements ActionListener { | |
| private final JProgressBar barra; | |
| public EventoOperacionLenta(JProgressBar b) { | |
| barra = b; | |
| } | |
| 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(); | |
| 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); | |
| barra.setValue(progreso); | |
| System.out.println("Agregando elemento " + i); | |
| } | |
| try ( FileOutputStream salida = new FileOutputStream(new File("eventoExcel.xlsx"))) { | |
| libro.write(salida); | |
| } | |
| System.out.println("arcrhivo Creado"); | |
| } | |
| @Override | |
| public void actionPerformed(ActionEvent e) { | |
| try { | |
| barra.setValue(0); | |
| this.generarExcel(); | |
| } catch (IOException ex) { | |
| Logger.getLogger(EventoOperacionLenta.class.getName()).log(Level.SEVERE, null, ex); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment