多张表struts2导入excel数据 其中一张表是一对多 ,故excel横向cell长度可变
来源:互联网 发布:php sql错误提示 编辑:程序博客网 时间:2024/04/30 04:17
注意图片中圈出部分是同一张表横向显示的
public String importExcle() {
TEmployee employee = (TEmployee) request.getSession().getAttribute("employee");
// 声明数据流
InputStream is = null;
if(employee!=null){
if (excel != null) {
//如果出错记住导入到的行和列
int hang=0;
try {
// 解析excel 2007 版本文件
is = new FileInputStream(excel);
XSSFWorkbook work = new XSSFWorkbook(is);
XSSFSheet sheet = work.getSheetAt(0);
int rows = sheet.getPhysicalNumberOfRows();
if (sheet != null) {
System.out.println("解析excel 2007版本文件");
/*--------------------------------------------------------------------------------------------------------------------------*/
// 导入啊 2007版
/*--------------------------------------------------------------------------------------------------------------------------*/
// 循环表的行,从第二行开始
for (int i = 1; i < rows; i++) {
hang=i;
XSSFRow row = sheet.getRow(i);
if (row == null) {// 判断是否为空
continue;
}
TImportantCustomer ic = new TImportantCustomer();
if (row.getCell((short)(0)) != null) {ic.setCompanyName(row.getCell((short) 0).getStringCellValue());}
if (row.getCell((short)(1)) != null) {ic.setLinkMan(row.getCell((short) 1).getStringCellValue());}
if (row.getCell((short)(2)) != null) { ic.setTell(row.getCell((short) 2).getStringCellValue());}
if (row.getCell((short)(3)) != null) {ic.setTelephone(String.valueOf(new BigDecimal(row.getCell((short) 3).getNumericCellValue()).toPlainString()));}
if (row.getCell((short)(4)) != null) { ic.setEmail(row.getCell((short) 4).getStringCellValue());}
if (row.getCell((short)(5)) != null) { ic.setQq(String.valueOf(new BigDecimal(row.getCell((short) 5).getNumericCellValue()).toPlainString()));}
if (row.getCell((short)(6)) != null) { ic.setCompanyDetail(row.getCell((short) 6).getStringCellValue());}
// 重要客户信息保存
ic.setCreateDate(new Date());
importantCustomerBiz.addicustomer(ic);
TNextFollowDetail nf = new TNextFollowDetail();
if (row.getCell((short)(7)) != null) { nf.setCustomerLevel((int)row.getCell((short) 7).getNumericCellValue());}
if (row.getCell((short)(8)) != null) { nf.setMainRequire(row.getCell((short) 8).getStringCellValue());}
if (row.getCell((short)(9)) != null) { nf.setNextFollowDetail(row.getCell((short) 9).getStringCellValue());}
if (row.getCell((short)(10)) != null) { nf.setNextFollowDate(row.getCell((short) 10).getDateCellValue());}
// 下次跟进保存
nf.setIcId(ic.getId());
nextFollowDetailBiz.addNextFollowDetail(nf);// 上次跟进时间未能填写(在导入历史记录时填写(查询最近时间))
TCustomerFollowDetail icf = null;
//计算循环次数
int k= (row.getLastCellNum()-10)/3;
for (int j = 0; j <k; j++) {
icf=new TCustomerFollowDetail();
if (row.getCell((short)(3*j+11))!= null) {
icf.setFollowMan(row.getCell((short)(3*j+11)).getStringCellValue());
}
if (row.getCell((short)(3*j+12)) != null) {
icf.setFollowDate(row.getCell((short)(3*j+12)).getDateCellValue());
}
if (row.getCell((short)(3*j+13)) != null) {
icf.setFollowContent(row.getCell((short)(3*j+13)).getStringCellValue());
}
if(StringUtils.hasText(icf.getFollowMan())||StringUtils.hasText(icf.getFollowContent())||icf.getFollowDate()!=null){
// 保存历史跟进
icf.setIcId(ic.getId());
customerFollowDetailBiz.addFollow(icf);
//添加上次跟进时间
TNextFollowDetail next=nextFollowDetailBiz.findByProperty(ic.getId());
//获取上次插入最近的时间
Date maxdate=customerFollowDetailBiz.findLastFollowDetailByDate(ic.getId());
next.setLastFollowDate(maxdate);
nextFollowDetailBiz.updateNextFollowDetail(next);
}
}
}
request.setAttribute("message", "导入成功(=^_^=)");
}
} catch (Exception e) {
/*--------------------------------------------------------------------------------------------------------------------------*/
// 导入啊 2003版
/*--------------------------------------------------------------------------------------------------------------------------*/
try {
// 解析excel 2003 版本文件
is = new FileInputStream(excel);
HSSFWorkbook work = new HSSFWorkbook(is);
HSSFSheet sheet = work.getSheetAt(0);
if (sheet != null) {
System.out.println("解析excel 2003 版本文件");
int rows = sheet.getPhysicalNumberOfRows();
// 循环表的行,从第二行开始
for (int i = 1; i < rows; i++) {
hang=i;
HSSFRow row = sheet.getRow(i);
if (row == null) {// 判断是否为空
continue;
}
TImportantCustomer ic = new TImportantCustomer();
if (row.getCell((short)(0)) != null) {ic.setCompanyName(row.getCell((short) 0).getStringCellValue());}
if (row.getCell((short)(1)) != null) {ic.setLinkMan(row.getCell((short) 1).getStringCellValue());}
if (row.getCell((short)(2)) != null) { ic.setTell(row.getCell((short) 2).getStringCellValue());}
if (row.getCell((short)(3)) != null) {ic.setTelephone(String.valueOf(new BigDecimal(row.getCell((short) 3).getNumericCellValue()).toPlainString()));}
if (row.getCell((short)(4)) != null) { ic.setEmail(row.getCell((short) 4).getStringCellValue());}
if (row.getCell((short)(5)) != null) { ic.setQq(String.valueOf(new BigDecimal(row.getCell((short) 5).getNumericCellValue()).toPlainString()));}
if (row.getCell((short)(6)) != null) { ic.setCompanyDetail(row.getCell((short) 6).getStringCellValue());}
// 重要客户信息保存
ic.setCreateDate(new Date());
importantCustomerBiz.addicustomer(ic);
TNextFollowDetail nf = new TNextFollowDetail();
if (row.getCell((short)(7)) != null) { nf.setCustomerLevel((int)row.getCell((short) 7).getNumericCellValue());}
if (row.getCell((short)(8)) != null) { nf.setMainRequire(row.getCell((short) 8).getStringCellValue());}
if (row.getCell((short)(9)) != null) { nf.setNextFollowDetail(row.getCell((short) 9).getStringCellValue());}
if (row.getCell((short)(10)) != null) { nf.setNextFollowDate(row.getCell((short) 10).getDateCellValue());}
// 下次跟进保存
nf.setIcId(ic.getId());
nextFollowDetailBiz.addNextFollowDetail(nf);// 上次跟进时间未能填写(在导入历史记录时填写(查询最近时间))
TCustomerFollowDetail icf = null;
//计算循环次数
int k= (row.getLastCellNum()-10)/3;
for (int j = 0; j <k; j++) {
icf=new TCustomerFollowDetail();
if (row.getCell((short)(3*j+11))!= null) {
icf.setFollowMan(row.getCell((short)(3*j+11)).getStringCellValue());
}
if (row.getCell((short)(3*j+12)) != null) {
icf.setFollowDate(row.getCell((short)(3*j+12)).getDateCellValue());
}
if (row.getCell((short)(3*j+13)) != null) {
icf.setFollowContent(row.getCell((short)(3*j+13)).getStringCellValue());
}
if(StringUtils.hasText(icf.getFollowMan())||StringUtils.hasText(icf.getFollowContent())||icf.getFollowDate()!=null){
// 保存历史跟进
icf.setIcId(ic.getId());
customerFollowDetailBiz.addFollow(icf);
//添加上次跟进时间
TNextFollowDetail next=nextFollowDetailBiz.findByProperty(ic.getId());
//获取上次插入最近的时间
Date maxdate=customerFollowDetailBiz.findLastFollowDetailByDate(ic.getId());
next.setLastFollowDate(maxdate);
nextFollowDetailBiz.updateNextFollowDetail(next);
}
}
}
request.setAttribute("message", "导入成功(=^_^=)");
}
} catch (Exception e1) {
request.setAttribute("message", "第"+hang+"行之后导入失败!");
e1.printStackTrace();
}
}
}
}else{
request.setAttribute("message", "登录超时!");
}
// 查询时对象中含有值对查询有误
if (icustomer != null) {
icustomer = null;
}
return icustomerList();
}
0 0
- 多张表struts2导入excel数据 其中一张表是一对多 ,故excel横向cell长度可变
- 【Mysql】将Excel表导入至Mysql的其中一张表
- 【Access2007】将Excel表导入至Access2007的其中一张已存在的表之中
- struts2-16导入导出Excel数据参考
- struts2中使用poi导入excel数据
- excel表中的数据导入到sqlServer中的一张表中
- Struts2 excel 导入 数据库
- struts2导入excel
- struts2导入excel
- struts2 excel文件导入
- struts2 EXCEL导入
- struts2 excel导入
- C#导入Excel表数据
- EXCEL数据导入数据库表
- EXCEL数据导入数据库表
- Mysql表导入excel数据
- 能实现一对多关联的通用EXCEL导入功能
- jxl 设置excel 默认是横向打印
- 直接拿来用!最火的Android开源项目(二)
- [OOP作业]设计一个栈,并用括号匹配检验
- 直接拿来用!最火的Android开源项目(完结篇)
- DragSortListView学习总结
- my_bank
- 多张表struts2导入excel数据 其中一张表是一对多 ,故excel横向cell长度可变
- 12-3-摩托车继承自行车和机动车
- NYOJ 37 回文字符串
- android瀑布流效果(仿蘑菇街)
- java之join/wait/notify/notifyall
- find命令不区分大小写
- failed to install Tomcat7 service解决办法
- JAVA UUID 生成 - jdonson - 博客园 http://www.cnblogs.com/jdonson/archive/2009/07/22/1528466.html
- linux常用查看硬件设备和系统信息命令