title: angularjs, spring boot, apache poi, can't generate excel document
body: <p>I'm trying to generate a Excel document. I'm using Apache POI version 3.14</p>
  
  <p>My controller:</p>
  
  <pre><code>@RestController
  @RequestMapping("/excel")
  public class ExcelRest {
  
      @Autowired
      private ProfilDao profilDao;
  
      @RequestMapping(value = "/get",  method = RequestMethod.GET)
      public ModelAndView getExcel(HttpServletRequest request, HttpServletResponse response) throws Exception{
  
  
          response.setHeader("Content-disposition", "attachment; filename=testExcel.xls");
          response.setContentType("application/vnd.ms-excel");
  
          // I get a List of Profil.
          List&lt;Profil&gt; profils = profilDao.findAll();
  
          return new ModelAndView(new ExcelProfilsBuilder(), "profils", profils);
  
      }
  }
  </code></pre>
  
  <p>My ModelView :</p>
  
  <pre><code>public class ExcelProfilsBuilder extends AbstractXlsView {
  
      @Override
      protected void buildExcelDocument(
          Map&lt;String, Object&gt; model, 
          Workbook workbook, 
          HttpServletRequest request,
          HttpServletResponse response) throws Exception {
  
          // On récupère les profiles provenant de la méthode REST 
          @SuppressWarnings("unchecked")
          List&lt;Profil&gt; profiles = (List&lt;Profil&gt;) model.get("profils");
  
          // create a new Excel sheet
          HSSFSheet sheet = (HSSFSheet) workbook.createSheet("Profiles");
          sheet.setDefaultColumnWidth(30);
  
          // create style for header cells
          CellStyle style = workbook.createCellStyle();
          Font font = workbook.createFont();
          font.setFontName("Arial");
          style.setFillForegroundColor(HSSFColor.BLUE.index);
          style.setFillPattern(CellStyle.SOLID_FOREGROUND);
          font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
          font.setColor(HSSFColor.WHITE.index);
          style.setFont(font);
  
          // create header row
          HSSFRow header = sheet.createRow(0);
  
          header.createCell(0).setCellValue("Nom");
          header.getCell(0).setCellStyle(style);
  
          header.createCell(1).setCellValue("Prénom");
          header.getCell(1).setCellStyle(style);
  
          // create data rows
          int rowCount = 1;
  
          for (Profil profil : profiles) {
              HSSFRow aRow = sheet.createRow(rowCount++);
              aRow.createCell(0).setCellValue(profil.getName());
              aRow.createCell(0).setCellValue(profil.getFirstname());
          }
  
      }
  
  }
  </code></pre>
  
  <p>To finish, I get it with AngularJs :</p>
  
  <pre><code>$http.get('/excel/get').then(
      function(response){
  
          var blob = new Blob([response], {type: "application/vnd.ms-excel"});
          var objectUrl = URL.createObjectURL(blob);
          window.open(objectUrl);
  
      }, 
      function(response){
  
          //error case
  
      }
  );
  </code></pre>
  
  <p>I don't know why, but when I receive my files, its name is, for exemple "8a4c6f51-3323-4f1b-bc4b-bd041801e66c.xls"</p>
  
  <p>and I have only one cells : [Object object]</p>
  
  <p>Edit : Another method which is doesn't works :</p>
  
  <pre><code>@RequestMapping(value = "/get/excel", method = RequestMethod.GET)
  @ResponseBody
  public void getExcel(HttpServletResponse response) throws Exception{
  
      response.setContentType("application/vnd.ms-excel");
      response.setHeader("Content-disposition", "attachment; filename=monFichier.xls");
  
      HSSFWorkbook workbook = new HSSFWorkbook();
      HSSFSheet sheet = workbook.createSheet("Utilisateurs");
      HSSFRow user = sheet.createRow(0);
      HSSFCell name = user.createCell(0);
      name.setCellValue("Test");
  
      try {
          workbook.write(response.getOutputStream());
      } catch (IOException e) {
  
      }
  
  
  }
  </code></pre>
  
  <p>Edit 2 : It's working if I'm using $http.post instead of $http.get :</p>
  
  <pre><code>    $http.post('/list/profil/get/excel',null, {responseType:'arraybuffer'})
        .success(function (response) {
            console.log("plop");
             var file = new Blob([response], {type: 'application/vnd.ms-excel'});
             var fileURL = URL.createObjectURL(file);
             window.open(fileURL);
      });
  </code></pre>
  
  <p>But I already have a bad filename.</p>