Download excel file 2003 or 2007 with Spring MVC

Friday, December 11th, 2015 (0 Comment)

We continue build spring mvc project with download excel file function, include two type is excel 2003 (xls) and excel 2007 (xlsx). We develop web page as below:

download excel page

download excel page

Step 1: create a download excel project with structure as following image:

project struct

project struct

  • we add com.demo.springmvc.view package to manage export data or file

Step 2: add libraries use for excel and config project

porn.xml: use org.apache.poi library

spring-excel-views.xml: config load class handle excel 2003 and 2007

  • line 6: call ExcelView2003.java class to write data for excel 2003
  • line 7: call ExcelView2007.java class to write data for excel 2007

servlet-context.xml: load file spring-excel-views.xml

web.xml: load servlet-context.xml file

Step 3: modify java files

Room.java: object to storing information

AbstractExcelPOIView.java: abstract class to distinguish between excel 2003 and excel 2007.

ExcelView2003.java: extends from AbstractExcelPOIView to write data for download excel 2003

ExcelView2007.java: extends from AbstractExcelPOIView to write data for download excel 2007

HelloWorldController.java: controller to control actions in web page

Step 4: we edit jsp files

hello.jsp:

index.jsp: redirect to hello page

Done.

Build and run project download excel. (if you do exercise following with these article, you need clean server runtime in eclipse and delete all tmp folder of cache jboss server or tomcat server before create new project if you build error or run web not effect)

Tags: , , , , , , ,

Related Posts

spring
How to create quartz spring dynamic in database
spring
Spring mvc mongodb crud users roles
spring
Java spring mvc tutorial on lvtutorial.com
spring
Angularjs spring mvc crud example

Related Posts

spring
How to create quartz spring dynamic in database
spring
Spring mvc mongodb crud users roles
spring
Java spring mvc tutorial on lvtutorial.com
spring
Angularjs spring mvc crud example

Leave a Reply

Your email address will not be published. Required fields are marked *