Spring Framework

Class AbstractJExcelView

  extended by org.springframework.context.support.ApplicationObjectSupport
      extended by org.springframework.web.context.support.WebApplicationObjectSupport
          extended by org.springframework.web.servlet.view.AbstractView
              extended by org.springframework.web.servlet.view.document.AbstractJExcelView
All Implemented Interfaces:
Aware, BeanNameAware, ApplicationContextAware, ServletContextAware, View

public abstract class AbstractJExcelView
extends AbstractView

Convenient superclass for Excel document views.

This class uses the JExcelAPI instead of POI. More information on JExcelAPI can be found on their website.


The file will be searched with locations in the following order:

For working with the workbook in the subclass, see Java Excel API site

As an example, you can try this snippet:

 protected void buildExcelDocument(
      Map<String, Object> model, WritableWorkbook workbook,
                HttpServletRequest request, HttpServletResponse response) {

         if (workbook.getNumberOfSheets() == 0) {
             workbook.createSheet("Spring", 0);
         WritableSheet sheet = workbook.getSheet("Spring");
         Label label = new Label(0, 0, "This is a nice label");
The use of this view is close to the AbstractExcelView class, just using the JExcel API instead of the Apache POI API.

Bram Smeets, Alef Arendsen, Juergen Hoeller
See Also:
AbstractExcelView, AbstractPdfView

Field Summary
Fields inherited from class org.springframework.web.servlet.view.AbstractView
Fields inherited from class org.springframework.context.support.ApplicationObjectSupport
Fields inherited from interface org.springframework.web.servlet.View
Constructor Summary
          Default Constructor.
Method Summary
protected abstract  void buildExcelDocument(java.util.Map<java.lang.String,java.lang.Object> model, jxl.write.WritableWorkbook workbook, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Subclasses must implement this method to create an Excel Workbook document, given the model.
protected  boolean generatesDownloadContent()
          Return whether this view generates download content (typically binary content like PDF or Excel files).
protected  jxl.Workbook getTemplateSource(java.lang.String url, javax.servlet.http.HttpServletRequest request)
          Create the workbook from an existing XLS document.
protected  void renderMergedOutputModel(java.util.Map<java.lang.String,java.lang.Object> model, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Renders the Excel view, given the specified model.
 void setUrl(java.lang.String url)
          Set the URL of the Excel workbook source, without localization part nor extension.
Methods inherited from class org.springframework.web.servlet.view.AbstractView
addStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getStaticAttributes, isExposePathVariables, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposePathVariables, setRequestContextAttribute, toString, writeToResponse
Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
Methods inherited from class org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Constructor Detail


public AbstractJExcelView()
Default Constructor. Sets the content type of the view to "application/vnd.ms-excel".

Method Detail


public void setUrl(java.lang.String url)
Set the URL of the Excel workbook source, without localization part nor extension.


protected boolean generatesDownloadContent()
Description copied from class: AbstractView
Return whether this view generates download content (typically binary content like PDF or Excel files).

The default implementation returns false. Subclasses are encouraged to return true here if they know that they are generating download content that requires temporary caching on the client side, typically via the response OutputStream.

generatesDownloadContent in class AbstractView
See Also:
AbstractView.prepareResponse(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse), ServletResponse.getOutputStream()


protected final void renderMergedOutputModel(java.util.Map<java.lang.String,java.lang.Object> model,
                                             javax.servlet.http.HttpServletRequest request,
                                             javax.servlet.http.HttpServletResponse response)
                                      throws java.lang.Exception
Renders the Excel view, given the specified model.

Specified by:
renderMergedOutputModel in class AbstractView
model - combined output Map (never null), with dynamic values taking precedence over static attributes
request - current HTTP request
response - current HTTP response
java.lang.Exception - if rendering failed


protected jxl.Workbook getTemplateSource(java.lang.String url,
                                         javax.servlet.http.HttpServletRequest request)
                                  throws java.lang.Exception
Create the workbook from an existing XLS document.

url - the URL of the Excel template without localization part nor extension
request - current HTTP request
the template workbook
java.lang.Exception - in case of failure


protected abstract void buildExcelDocument(java.util.Map<java.lang.String,java.lang.Object> model,
                                           jxl.write.WritableWorkbook workbook,
                                           javax.servlet.http.HttpServletRequest request,
                                           javax.servlet.http.HttpServletResponse response)
                                    throws java.lang.Exception
Subclasses must implement this method to create an Excel Workbook document, given the model.

model - the model Map
workbook - the Excel workbook to complete
request - in case we need locale etc. Shouldn't look at attributes.
response - in case we need to set cookies. Shouldn't write to it.
java.lang.Exception - in case of failure

Spring Framework