title: Return Excel downloadable file from Spring
body: <p>So I have a Spring controller, and I'd like to create an Excel file and return it so that it is downloaded by the browser. </p>
  
  <p>I'm using JEXcelApi. </p>
  
  <p>This is my controller code </p>
  
  <pre><code>@RequestMapping(value="/excel/cols/{colString}/rows/{rowString}/", method = RequestMethod.GET)
  @ResponseBody
  public ResponseEntity&lt;String&gt; exportExcel(HttpServletResponse response,
      @PathVariable List&lt;String&gt; colString,
      @PathVariable List&lt;String&gt; rowString) throws JSONException, IOException, WriteException {
      WritableWorkbook workbook = Workbook.createWorkbook(new File("exported.xls"));
      WritableSheet sheet = workbook.createSheet("Exported",0);
      String[] cols = colString.get(0).split(",");
      String[] rows = rowString.get(0).split(","); 
      for(int i = 0; i &lt; cols.length;i++){
          Label label = new Label(i,0, cols[i]);
          sheet.addCell(label);
      }
      int excelCol = 0;
      int excelRow = 1;
      for(int i = 0; i &lt; rows.length;i++){
          Label label = new Label(excelCol,excelRow, rows[i]);
          sheet.addCell(label);
          excelCol++;
          if((i+1) % cols.length == 0){
              excelCol = 0;
              excelRow++;
          }
      }
      workbook.write();
      workbook.close();
      return null;
  }
  </code></pre>
  
  <p>How do I do that? I suspect there's some content header I can set. I know one method is to use Spring's Abstract Excel view class, but is there a simpler method? </p>