title: apache POI - get size of generated excel file
body: <p>I'm using <a href="http://poi.apache.org/" rel="noreferrer">Apache POI</a> for generating excel file in my spring mvc application. here is my spring action:</p>
  
  <pre><code> @RequestMapping(value = "/excel", method = RequestMethod.POST)
  public void companyExcelExport(@RequestParam String filter, @RequestParam String colNames, HttpServletResponse response) throws IOException{
      XSSFWorkbook workbook = new XSSFWorkbook();
      //code for generate excel file
      //....
  
      response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
      response.setHeader("Content-Disposition", "attachment; filename=test.xlsx");
      workbook.write(response.getOutputStream());
  
      response.setHeader("Content-Length", "" + /* How can i access workbook size here*/);
  }
  </code></pre>
  
  <p>I used <code>XSSFWorkbook</code> because i need to generate Excel 2007 format. but my problem is <code>XSSFWorkbook</code> does not have <code>getBytes</code> or <code>getSize</code> method. How can i calculate size of generated xlsx file?</p>
  
  <p>EDIT: I used <code>ByteArrayOutputStream</code> like here:</p>
  
  <pre><code>ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  workbook.write(response.getOutputStream()); 
  workbook.write(byteArrayOutputStream);
  response.setHeader("Content-Length", "" + byteArrayOutputStream.size());
  </code></pre>