title: How to download an excel file in Spring RestController
body: <p>I am using Apache POI to generate <strong>.xlsx</strong> file.</p>
  
  <p>I would like to return that file from Spring controller. Here's what I've done so far:</p>
  
  <p>Controller:</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.GET)
      public HttpEntity&lt;byte[]&gt; createExcelWithTaskConfigurations(HttpServletResponse response) throws IOException {
          byte[] excelContent = excelService.createExcel();
  
          HttpHeaders header = new HttpHeaders();
          header.setContentType(new MediaType("application", "vnd.openxmlformats-officedocument.spreadsheetml.sheet"));
          header.set(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=my_file.xls");
          header.setContentLength(excelContent.length);
  
          return new HttpEntity&lt;&gt;(excelContent, header);
      }
  </code></pre>
  
  <p>Is it possible to return actual excel file from rest controller so user can download it to his computer ? As for now controller returning byte[] but I would like to return it actual file. How can I achieve that ?</p>