title: Use AbstractJExcelView to generate excel file and send through MailSender in Spring Framework
body: <p>Currently my project uses a Controller class and utilizes AbstractJExcelView Class to generate an Excel Report which gives a prompt to user to either open or save the excel file. Basicall it uses http protocol for calling the controller.
  Now what I need to do is generate the same excel file during (Spring) batch jobs and send it as an attachment directly through email. We're using org.springframework.mail.MailSender for sending mails. 
  I'm not supposed to use any other external API and I have no clue where to start from.</p>
  
  <p>This is a similar code of what we're doing :-</p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>public class RevenueReportController extends AbstractController{
  
  @Override
  protected ModelAndView handleRequestInternal(HttpServletRequest request,
      HttpServletResponse response) throws Exception {
  
      String output =
          ServletRequestUtils.getStringParameter(request, "output");
  
      //dummy data
      Map&lt;String,String&gt; revenueData = new HashMap&lt;String,String&gt;();
      revenueData.put("Jan-2010", "$100,000,000");
      revenueData.put("Feb-2010", "$110,000,000");
      revenueData.put("Mar-2010", "$130,000,000");
      revenueData.put("Apr-2010", "$140,000,000");
      revenueData.put("May-2010", "$200,000,000");
  
      if(output ==null || "".equals(output)){
          //return normal view
          return new ModelAndView("RevenueSummary","revenueData",revenueData);
  
      }else if("EXCEL".equals(output.toUpperCase())){
          //return excel view
          return new ModelAndView("ExcelRevenueSummary","revenueData",revenueData);
  
      }else{
          //return normal view
          return new ModelAndView("RevenueSummary","revenueData",revenueData);
  
      }   
  }
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>public class ExcelRevenueReportView extends AbstractJExcelView{
  
  @Override
  protected void buildExcelDocument(Map model, WritableWorkbook workbook,
     HttpServletRequest request, HttpServletResponse response)
     throws Exception {
  
     Map&lt;String,String&gt; revenueData = (Map&lt;String,String&gt;) model.get("revenueData");
     WritableSheet sheet = workbook.createSheet("Revenue Report", 0);
  
         sheet.addCell(new Label(0, 0, "Month"));
         sheet.addCell(new Label(1, 0, "Revenue"));
  
         int rowNum = 1;
     for (Map.Entry&lt;String, String&gt; entry : revenueData.entrySet()) {
      //create the row data
      sheet.addCell(new Label(0, rowNum, entry.getKey()));
          sheet.addCell(new Label(1, rowNum, entry.getValue()));
          rowNum++;
         }
     }
  </code></pre>
  
  <p>}</p>
  
  <p>Is there any way to do that ? I need to generate the excel sheet with passed and failed job data. I can handle populating and creating the file but I have no idea how to generate the excel in buffer or may be in some temp directory which could again be attached while sending the mail. The user is not required to respond to any prompts. Neither are we going to use any http request.</p>
  
  <p>Thanks in advance!</p>