Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 23, 2022 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/70ef8f7af82cbaad83718675428c1942 to your computer and use it in GitHub Desktop.
Save parzibyte/70ef8f7af82cbaad83718675428c1942 to your computer and use it in GitHub Desktop.
Workbook libro = new XSSFWorkbook();
final String nombreArchivo = "Mi archivo creado con Java.xlsx";
Sheet hoja = libro.createSheet("Hoja 1");
Row primeraFila = hoja.createRow(0);
Cell primeraCelda = primeraFila.createCell(0);
primeraCelda.setCellValue("Yo voy en la primera celda y primera fila");
File directorioActual = new File(".");
String ubicacion = directorioActual.getAbsolutePath();
String ubicacionArchivoSalida = ubicacion.substring(0, ubicacion.length() - 1) + nombreArchivo;
FileOutputStream outputStream;
try {
outputStream = new FileOutputStream(ubicacionArchivoSalida);
libro.write(outputStream);
libro.close();
System.out.println("Libro guardado correctamente");
} catch (FileNotFoundException ex) {
System.out.println("Error de filenotfound");
} catch (IOException ex) {
System.out.println("Error de IOException");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment