When i create and download file using AbstractExcelView in spring application, it will download as .html file.But when i change its extension as .xls manually ,it shows expected result. My code for AbstractExcelView is :
public class ExcelRevenueReportView extends AbstractExcelView {
@Override
protected void buildExcelDocument(Map model, HSSFWorkbook workbook,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
Map<String, String> revenueData = (Map<String, String>) model
.get("revenueData");
// create a wordsheet
HSSFSheet sheet = workbook.createSheet("Revenue Report");
HSSFRow header = sheet.createRow(0);
header.createCell(0).setCellValue("Month");
header.createCell(1).setCellValue("Revenue");
int rowNum = 1;
for (Map.Entry<String, String> entry : revenueData.entrySet()) {
// create the row data
HSSFRow row = sheet.createRow(rowNum++);
row.createCell(0).setCellValue(entry.getKey());
row.createCell(1).setCellValue(entry.getValue());
}
}
}
The context configuration file :dispatcher-servlet.xml is
<beans:bean name="/index.html" class="com.my.report.HomeController">
</beans:bean>
<beans:bean class="org.springframework.web.servlet.view.XmlViewResolver">
<beans:property name="location" value="/WEB-INF/spring-excel-views.xml" />
<beans:property name="order" value="0" />
</beans:bean>