org.springframework.web.servlet.view.document
Class AbstractExcelView
org.springframework.context.support.ApplicationObjectSupport
|
+--org.springframework.web.context.support.WebApplicationObjectSupport
|
+--org.springframework.web.servlet.view.AbstractView
|
+--org.springframework.web.servlet.view.document.AbstractExcelView
- public abstract class AbstractExcelView
- extends AbstractView
Convenient superclass for Excel-document views.
Properties:
url (optional): The url of an existing Excel document to pick as a starting point.
It is done without localization part nor the .xls extension.
The file will be searched with names in the following order:
[url]_[language][country].xls
[url]_[language].xls
[url].xls
For work with th workBook in the subclass, see Jakarta's POI site
As an example, you can try this snippet:
protected void buildExcelDocument(
Map model,
HSSFWorkbook wb,
HttpServletRequest request,
HttpServletResponse response )
{
// AModel aModel = ( AModel ) model.get( "amodel" );
HSSFSheet sheet;
HSSFRow sheetRow;
HSSFCell cell;
// Go to the first sheet
// getSheetAt: only if wb is created from an existing document
//sheet = wb.getSheetAt( 0 );
sheet = wb.createSheet("Spring");
sheet.setDefaultColumnWidth((short)12);
// write a text at A1
cell = getCell( sheet, 0, 0 );
setText(cell,"Spring POI test");
// Write the current date at A2
HSSFCellStyle dateStyle = wb.createCellStyle( );
dateStyle.setDataFormat( HSSFDataFormat.getBuiltinFormat( "m/d/yy" ) );
cell = getCell( sheet, 1, 0 );
cell.setCellValue( new Date() );
cell.setCellStyle( dateStyle );
// Write a number at A3
getCell( sheet, 2, 0 ).setCellValue( 458 );
// Write a range of numbers
sheetRow = sheet.createRow( 3 );
for (short i = 0; i<10; i++) {
sheetRow.createCell(i).setCellValue( i*10 );
}
}
Don't forget to add on web.xml:
<servlet-mapping>
<servlet-name>[your Spring servlet]</servlet-name>
<url-pattern>*.xls</url-pattern>
</servlet-mapping>
The use of this view is close to the AbstractPdfView- Author:
- Jean-Pierre Pawlak
- See Also: AbstractPdfView
| Method Summary |
void | setUrl(String url) Sets the url of the Excel workbook source without localization part nor extension. |
AbstractExcelView
public AbstractExcelView()
setUrl
public void setUrl(String url)
- Sets the url of the Excel workbook source without localization part nor extension.
to Class java.lang.String
to Class java.lang.String
to Class java.lang.String