码迷,mamicode.com
首页 > 其他好文 > 详细

设备资源管理系统-jxl报表

时间:2014-07-02 20:32:42      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   java   color   使用   

设备资源管理系统-jxl报表

  • 引入导入的模板

bubuko.com,布布扣

  • 部分代码

1、引入使用jxl报表技术的jar包

2、导入java文件GenerateSqlFromExcel.java

3、导入jsp文件userImport.jsp文件,用于导入excel的文件页面

4、在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导入" name="BT_Import"

       onclick="openWindow(‘system/elecUserAction_importpage.do‘,‘700‘,‘400‘)">

     </td>

5、在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导入" name="BT_Import"

       onclick="openWindow(‘system/elecUserAction_importpage.do‘,‘700‘,‘400‘)">

     </td>

6、在struts.xml的配置文件中,添加:

   <!-- 2011-12-12,从excel文件中读取数据,存入数据库中 -->

   <result name="importpage">

    /WEB-INF/page/system/userImport.jsp

   </result>

   <result name="importdata">

    /WEB-INF/page/system/userImport.jsp

   </result>

7、在ElecUserForm中添加file属性:

   private File file;

   public File getFile() {

     return file;

   }

   public void setFile(File file) {

     this.file = file;

   }

8、在ElecUserAction中添加2个方法

   public String importpage(){

       return "importpage";

   }

   public String importdata(){

     elecUserService.importExcelData(elecUserForm);

     return "importdata";

   }

9、在ElecUserServiceImpl中添加方法:

   @Transactional(isolation=Isolation.DEFAULT,propagation=Propagation.REQUIRED,readOnly=false)

 public void importExcelData(ElecUserForm 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 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("从excel文件中读取数据,导入到数据库有误!");

  }

 

 }

 

设备资源管理系统-jxl报表,布布扣,bubuko.com

设备资源管理系统-jxl报表

标签:style   blog   http   java   color   使用   

原文地址:http://www.cnblogs.com/yangml/p/3819310.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!