xxxxxxxxxx
return this.http.get("/ExportExcel/", this.commonRepository.getRequestOptionsForCSV(URL.BEARER)).map(res => {
return {
filename: 'customers.csv',
data: res.blob()
};
});
xxxxxxxxxx
@GetMapping("/ExportExcel/{date}")
public void excelExportReport(@RequestParam Date date, HttpServletResponse httpServletResponse) throws IOException {
List<InterfaceTable> interfaceTables=interfaceTableRepo.afficheAHT(date);
ByteArrayInputStream in =ExportExcel.ahtToExcel(interfaceTables);
byte[] byteArray = new byte[in.available()];
try {
byteArrayInputStream.read(byteArray);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ByteArrayOutputStream out = new ByteArrayOutputStream(byteArray.length);
out.write(byteArray, 0, byteArray.length);
httpServletResponse.setContentType("text/csv");
httpServletResponse.addHeader("Content-Disposition", "attachment; filename=customers.csv");
OutputStream os;
try {
os = httpServletResponse.getOutputStream();
out.writeTo(os);
os.flush();
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
xxxxxxxxxx
this.customerService.generateReportCsv(this.receiptReportPage.value).subscribe((results)=>{
console.log(results);
var url = window.URL.createObjectURL(results.data);
var a = document.createElement('a');
document.body.appendChild(a);
a.setAttribute('style', 'display: none');
a.setAttribute('target', 'blank');
a.href = url;
a.download = results.filename;
a.click();
window.URL.revokeObjectURL(url);
a.remove();
});