Page section
<form method= "POST" name = "Test" enctype= "Multipart/form-data" >
<input type= "File" name= "file"/>
</form>
Entity class section
Public Class test{
Private String ID;
private String name;
Private String address;
The following is the Get, set method (omitted)
}
Action section
Get file by strusts2
private file file;
Private String FileName;
Private String Filecontenttype;
Add a Get, set method
Get Workbook Object
Xssfworkbook WorkBook = new Xssfworkbook (File.getinputstream ());
define Worksheet
Xssfsheet workSheet = null;
Defines the data obtained from Excel to be stitched into a list object
List<test> listtest=new arraylist<test> ();
Get the number of sheet pages
int sheetcount = Workbook.getnumberofsheets ();
for (int i=0;i<sheetcount;i++) {
Get the first I sheet
WorkSheet = Workbook.getsheetat (i);
Gets the number of rows for the sheet page
for (int j=0;j<worksheet.getphysicalnumberofrows (); j + +) {
Get Line J
Xssfrow row = Worksheet.getrow (j);
Test test=new test ();
Row.getcell (0) Get data for cell 1th of row J
Test.setid (Row.getcell (0) ==null? "": Row.getcell (0). toString (). Trim ());
Judging if the 2nd Act number format turns into a string
if (Row.getcell (1)!=null && Row.getcell (1). Getcelltype () = = Xssfcell.cell_type_numeric) {
Row.getcell (1). Setcelltype (cell.cell_type_string);
}
Test.setname (Row.getcell (1) ==null? "": Row.getcell (1). toString (). Trim ());
Test.setaddress (Row.getcell (2) ==null? "": Row.getcell (2). toString (). Trim ());
Listtest.add (test);
}
}
Ibatis part
<insert id= "Export" parameterclass= "Java.util.List" >
<! [cdata[
Insert All
]]>
<iterate conjunction= "" >
<! [cdata[
into Test (id,name,address)
Values
(#listTest [].id#, #listTest [].name#, #listTest [].address#]
]]>
</iterate>
<! [cdata[
Select 1 from dual
]]>
</insert>
2007 version of Excel multiple sheet page data is batched into the database through Ibatis