首页 > 代码库 > 设备资源管理系统-jxl报表
设备资源管理系统-jxl报表
设备资源管理系统-jxl报表
- 引入导入的模板
- 部分代码
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="http://www.mamicode.com/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="http://www.mamicode.com/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 = http://www.mamicode.com/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文件中读取数据,导入到数据库有误!");
}
}