Имя файла экспорта Spring Boot и Angular Excel

#angular #spring-boot #export-to-excel

Вопрос:

Я выполняю экспорт excel с помощью Spring Boot и Angular. Когда я загружаю его с помощью Postman на стороне загрузки Spring, имя файла записывается как «users_17-06-2021.xlsx». Когда я интегрирую его с Angular, он получает случайное имя, например «9bebc6b8-2633-47d7-8a5e-00c4577a0fcc.xls». Как я могу решить эту проблему. Что мне нужно сделать, чтобы загрузить его с именем в разделе весенней загрузки?

Пружинный ботинок

  @GetMapping("/export")
        public void exportToExcel(HttpServletResponse response) throws IOException {
    
            DateFormat dateFormatter = new SimpleDateFormat("dd-MM-yyyy");
            String currentDateTime = dateFormatter.format(new Date());
            response.setContentType("application/octet-stream");
            response.setCharacterEncoding("UTF-8");
            String headerKey = "Content-Disposition";
            String headerValue = "attachment; filename=users_"   currentDateTime   ".xlsx";
            response.setHeader(headerKey, headerValue);
            List<User> users= service.findAll();
            ExcelExporter excelExporter = new ExcelExporter(users);
            excelExporter.export(response);
    
        }
        
 

Угловая составляющая.ts

     onSubmitExcel() {
      this.service.exportExcel().subscribe(response => {
        let file = new Blob([response], { type: 'application/vnd.ms-excel' });
        var fileURL = URL.createObjectURL(file);
        window.open(fileURL);
      })

  }
 

Angular.service.ts

   exportExcel(): Observable<any> {
    return this.http.get<any>(apiHost   '/export' { responseType: 'arraybuffer' as 'json' }).pipe(
      map((data: any) => {
        return data;
      })
    );
  }