Device Resource Management System-jxl report
1. Introduce jar packages using jxl report Technology
2. Import the Java file generatesqlfromexcel. Java
3. Import the JSP file userimport. jsp, which is used to import the Excel file page
4. Add the following in userindex. jsp:
<TD class = "ta_01" align = "right">
<Input style = "font-size: 12px; color: black; Height = 20; width = 80 "id =" bt_import "type =" button "value =" Excel import "name =" bt_import"
Onclick = "OpenWindow ('System/elecuseraction_importpage.do ', '123', '123')">
</TD>
5. Add the following in userlist. jsp:
<TD class = "ta_01" align = "right">
<Input style = "font-size: 12px; color: black; Height = 20; width = 80 "id =" bt_import "type =" button "value =" Excel import "name =" bt_import"
Onclick = "OpenWindow ('System/elecuseraction_importpage.do ', '123', '123')">
</TD>
6. In the Struts. xml configuration file, add:
<! -- 2011-12-12: read data from an Excel file and store it in a database -->
<Result name = "importpage">
/WEB-INF/page/system/userimport. jsp
</Result>
<Result name = "importdata">
/WEB-INF/page/system/userimport. jsp
</Result>
7. Add the file attribute to elecuserform:
Private file;
Public file GetFile (){
Return file;
}
Public void setfile (File file ){
This. File = file;
}
8. Add two methods to elecuseraction.
Public String importpage (){
Return "importpage ";
}
Public String importdata (){
Elecuserservice. importexceldata (elecuserform );
Return "importdata ";
}
9. Add the method in elecuserserviceimpl:
@ Transactional (isolation = isolation. Default, propagation = propagation. required, readonly = false)
Public void importexceldata (elecuserform ){
Try {
File file = elecuserform. GetFile ();
Generatesqlfromexcel fromexcel = new generatesqlfromexcel ();
Arraylist <string []> List = fromexcel. generatestationbugsql (File );
Md5keybean bean = new md5keybean ();
For (INT I = 0; list! = NULL & I <list. Size (); I ++ ){
String [] DATA = list. Get (I );
Elecuser = new elecuser ();
Elecuser. setlogonname (data [0]. tostring ());
Elecuser. setlogonpwd (bean. getkeybeanofstr (data [1]. tostring ()));
Elecuser. setusername (data [2]. tostring ());
Elecuser. setsexid (data [3]. tostring ());
Elecuser. setjctid (data [4]. tostring ());
Elecuser. setaddress (data [5]. tostring ());
Elecuser. setisduty (data [6]. tostring ());
Elecuser. setbirthday (stringhelper. stringconvertdate (data [7]. tostring ()));
Elecuserdao. Save (elecuser );
}
} Catch (exception e ){
Throw new runtimeexception ("An error occurred while reading data from the Excel file and importing it to the database! ");
}
}