Import/Read excel file 2003 or 2007 with Spring MVC

Monday, December 14th, 2015 (12 Comments)

To continue with previous download excel file article, we develop import/read excel file 2003 (xls) or 2007 (xlsx).

We will need some libraries as org.apache.poi and commons-fileupload to access excel file.

We will build web page as below:

page read excel

page read excel

Step 1: create new spring mvc project as following image:

project struct

project struct

  • You need to create 2 files excel 2003 and 2007, example:
  • UserInfo.xls: read excel 2003
    • 1 usernam1 10/22/2015
      2 usernam2 10/23/2015
      3 usernam3 10/24/2015
  • UserInfo.xlsx: read excel 2007
    • 1 usernam1 11/22/2015
      2 usernam2 11/23/2015
      3 usernam3 11/24/2015

Step 2: add org.apache.poi library to read excel and commons-fileupload library use upload excel temporary file

porn.xml:

servlet-context.xml: config servlet of spring

config-upload.xml: must config upload file to server read file from location temporary of server

web.xml: load some files configuration

Step 3: modify java files

UserInfo.java: entity class to storing information of excel file after read excel

HelloWorldController.java: mange upload and read excel files

Step 4: edit page screen for end users

hello.jsp: page import and read excel

index.jsp: redirect root page to hello page

Done !

Build and run.

You can review more detail excel file in java in Write read excel file 2003 or 2007 in java with many CellStyles article.

If you do all article in category spring mvc, you can do 2/3 project or system web application in your company. I will continue posting step by step simply project corresponding to each function of company’s system.

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

12 Comments

  1. Siddharth Agrawal

    Can you tell me how to compare 2 excel sheets using java spring framework and return the mismatch in another excel sheet after reading the excel sheet.

    1. Vivian Post author

      Hi Siddharth Agrawal,
      I think you can get sheet 1 & sheet 2 and then compare cell by cell between two sheets, if at least one cell is not the same then return status Mismatch and create new sheet include content of sheet 1 & sheet 2 …

  2. esawr

    Hi,

    Can u tell me about how to upload excel sheet in to data base using Spring MVC.

    1. Vivian Post author

      Hi Lalitha,
      This program only read data from excel file (it will save in temp folder of OS), it does not save file into path where we want store.
      We want to save files after upload, please review article Upload file simply with Spring MVC

  3. raveendra

    Hi Vivian
    i have requirment some thing like read excel and persisti into database useing spring boot with apache poi , do have any examples related this

  4. Miguel

    This is a nice tutorial however just a couple of code issues I encountered.
    This line caused issues XSSFRow row = worksheet.getRow(i++);
    I changed to XSSFRow row = worksheet.getRow(i);
    Also this line caused problems
    while (i <= worksheet.getLastRowNum()) {
    I changed it to
    while (i < worksheet.getLastRowNum()) {

    Everything else seem to work as advertised.

    1. Vivian Post author

      Hi Miguel, thanks your comment. I have checked code again and if change with your code then will be loop so we do not have increase i.
      I also run again project and it still worked ok. You can check out project in https://github.com/lvtutorial/spring-upload-excel-db.
      If the project is still encountered issue, pls you give detail info.

  5. abdul

    my requirement is read the excel sheet data and store into database using spring and hibernate

Leave a Reply

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