Package org.springframework.web.servlet.view.document

# Class AbstractXlsView

java.lang.Object
org.springframework.context.support.ApplicationObjectSupport
org.springframework.web.context.support.WebApplicationObjectSupport
org.springframework.web.servlet.view.AbstractView
org.springframework.web.servlet.view.document.AbstractXlsView

All Implemented Interfaces:
  `org.springframework.beans.factory.Aware`, `org.springframework.beans.factory.BeanNameAware`, `org.springframework.context.ApplicationContextAware`, `org.springframework.web.context.ServletContextAware`, `View`

Direct Known Subclasses:
  `AbstractXlsxView`

public abstract class AbstractXlsView extends AbstractView
Convenient superclass for Excel document views in traditional XLS format. Compatible with Apache POI 3.5 and higher.

For working with the workbook in the subclass, see Apache's POI site

Since:
  4.2
Author:
  Juergen Hoeller

## Field Summary

### Fields inherited from class org.springframework.web.servlet.view.AbstractView

`DEFAULT_CONTENT_TYPE`

### Fields inherited from class org.springframework.context.support.ApplicationObjectSupport

`logger`

### Fields inherited from interface org.springframework.web.servlet.View

`PATH_VARIABLES, RESPONSE_STATUS_ATTRIBUTE, SELECTED_CONTENT_TYPE`

## Constructor Summary

Constructors
Constructor
Description
`AbstractXlsView()`
Default Constructor.

## Method Summary

Modifier and Type
Method
Description
`protected abstract void`
`buildExcelDocument(Map<String,Object> model, org.apache.poi.ss.usermodel.Workbook workbook, HttpServletRequest request, HttpServletResponse response)`
Application-provided subclasses must implement this method to populate the Excel workbook document, given the model.
`protected org.apache.poi.ss.usermodel.Workbook`
`createWorkbook(Map<String,Object> model, HttpServletRequest request)`
Template method for creating the POI `Workbook` instance.
`protected boolean`
`generatesDownloadContent()`
Return whether this view generates download content (typically binary content like PDF or Excel files).
`protected final void`
`renderMergedOutputModel(Map<String,Object> model, HttpServletRequest request, HttpServletResponse response)`
Renders the Excel view, given the specified model.
`protected void`
`renderWorkbook(org.apache.poi.ss.usermodel.Workbook workbook, HttpServletResponse response)`
The actual render step: taking the POI `Workbook` and rendering it to the given response.

### Methods inherited from class org.springframework.web.servlet.view.AbstractView

`addStaticAttribute, createMergedOutputModel, createRequestContext, createTemporaryOutputStream, exposeModelAsRequestAttributes, formatViewName, getAttributesMap, getBeanName, getContentType, getRequestContextAttribute, getRequestToExpose, getStaticAttributes, isExposePathVariables, prepareResponse, render, setAttributes, setAttributesCSV, setAttributesMap, setBeanName, setContentType, setExposeContextBeansAsAttributes, setExposedContextBeanNames, setExposePathVariables, setRequestContextAttribute, setResponseContentType, 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, obtainApplicationContext, requiredContextClass, setApplicationContext`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### AbstractXlsView

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

## Method Details

### generatesDownloadContent

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.

Overrides:
  `generatesDownloadContent` in class `AbstractView`
See Also:
  - `AbstractView.prepareResponse(jakarta.servlet.http.HttpServletRequest, jakarta.servlet.http.HttpServletResponse)`
  - `ServletResponse.getOutputStream()`

### renderMergedOutputModel

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

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

### createWorkbook

protected org.apache.poi.ss.usermodel.Workbook createWorkbook(Map<String,Object> model, HttpServletRequest request)
Template method for creating the POI `Workbook` instance.

The default implementation creates a traditional `HSSFWorkbook`. Spring-provided subclasses are overriding this for the OOXML-based variants; custom subclasses may override this for reading a workbook from a file.

Parameters:
  `model` - the model Map
  `request` - current HTTP request (for taking the URL or headers into account)
Returns:
  the new `Workbook` instance

### renderWorkbook

protected void renderWorkbook(org.apache.poi.ss.usermodel.Workbook workbook, HttpServletResponse response) throws IOException
The actual render step: taking the POI `Workbook` and rendering it to the given response.

Parameters:
  `workbook` - the POI Workbook to render
  `response` - current HTTP response
Throws:
  `IOException` - when thrown by I/O methods that we're delegating to

### buildExcelDocument

protected abstract void buildExcelDocument(Map<String,Object> model, org.apache.poi.ss.usermodel.Workbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception
Application-provided subclasses must implement this method to populate the Excel workbook document, given the model.

Parameters:
  `model` - the model Map
  `workbook` - the Excel workbook to populate
  `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.
Throws:
  `Exception`