Device Resource Management System-jxl report

Source: Internet
Author: User

Device Resource Management System-jxl report

  • Import Template

  • Some code

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! ");

}

 

}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.