Skip to content

Instantly share code, notes, and snippets.

@mistergamarra
Last active October 1, 2020 05:54
Show Gist options
  • Save mistergamarra/1cc8f505b8ede46ebeb5d0dc2ecc4f16 to your computer and use it in GitHub Desktop.
Save mistergamarra/1cc8f505b8ede46ebeb5d0dc2ecc4f16 to your computer and use it in GitHub Desktop.
This requieres FileCreator.java in order to do something
@Controller
public class ArchivoApiController {
@Autowired
private FileCreator fileCreator;
@GetMapping("/report")
public ResponseEntity<byte[]> generateReport(String filename) {
HttpHeaders header = new HttpHeaders();
header.setContentType("application/octet-stream");
header.setContentLength(bytes.length);
header.set(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + (filename + ".xlsx") + "\"");
byte[] file = genericCall();
return new ResponseEntity<byte[]>(file, headers, HttpStatus.OK);
}
private byte[] genericCall() {
XSSFSheet hoja = fileCreator.aperturarWorkbook("hoja1");
// le agregas filas y columnas a la "hoja"
return fileCreator.crearExcel(hoja.getWorkbook()); // pasas el worbook de "la hoja"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment