public String export(){
List<Contacts> contactslist = contactsService.findAll();
Workbook wb = new HSSFWorkbook();
Sheet st = wb.createSheet("联系表");
Row topRow = st.createRow(0);
Cell c1 = topRow.createCell(0);
c1.setCellValue("name");
Cell c2 = topRow.createCell(1);
c2.setCellValue("companyname");
Cell c3 = topRow.createCell(2);
c3.setCellValue("weibo");
Cell c4 = topRow.createCell(3);
c4.setCellValue("weibotype");
Cell c5 = topRow.createCell(4);
c5.setCellValue("content");
Cell c6 = topRow.createCell(5);
c6.setCellValue("view");
Cell c7 = topRow.createCell(6);
c7.setCellValue("address");
Cell c8 = topRow.createCell(7);
c8.setCellValue("createtime");
Cell c10 = topRow.createCell(8);
c10.setCellValue("tel");
Cell c11 = topRow.createCell(9);
c11.setCellValue("im");
Cell c12 = topRow.createCell(10);
c12.setCellValue("mail");
Cell c13 = topRow.createCell(11);
c13.setCellValue("website");
for (int i = 1; i < contactslist.size()+1; i++) {
Row r = st.createRow(i);
Cell n = r.createCell(0);
n.setCellValue(contactslist.get(i-1).getName());
Cell cn = r.createCell(1);
cn.setCellValue(contactslist.get(i-1).getCompanyname());
Cell w = r.createCell(2);
w.setCellValue(contactslist.get(i-1).getWeibo());
Cell wt = r.createCell(3);
wt.setCellValue(contactslist.get(i-1).getWeibotype());
Cell v = r.createCell(4);
v.setCellValue(contactslist.get(i-1).getContent());
Cell c = r.createCell(5);
c.setCellValue(contactslist.get(i-1).getView());
Cell a = r.createCell(6);
a.setCellValue(contactslist.get(i-1).getAddress());
Cell ct = r.createCell(7);
ct.setCellValue(contactslist.get(i-1).getCreatetime());
Set<Tel> ts = contactslist.get(i-1).getTelSet();
String str ="";
for (Tel tel : ts) {
str +=tel.getTel()+",";
}
Cell t = r.createCell(8);
t.setCellValue(str);
Set<Im> im = contactslist.get(i-1).getImSet();
String str1 = "";
for (Im im2 : im) {
str1 +=im2.getIm()+",";
}
Cell imm = r.createCell(9);
imm.setCellValue(str1);
Set<Mail> ms = contactslist.get(i-1).getMailSet();
String str2 = "";
for (Mail mail : ms) {
str2 +=mail.getMail()+",";
}
Cell m = r.createCell(10);
m.setCellValue(str2);
Set<Website> ws = contactslist.get(i-1).getWebsiteSet();
String str3 = "";
for (Website website : ws) {
str3 +=website.getWebsite()+",";
}
Cell wes = r.createCell(11);
wes.setCellValue(str3);
}
try {
wb.write(new FileOutputStream("e:/a.xls"));
return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
return ERROR;
}
}
//����
public String imp(){
try {
Workbook wb = new HSSFWorkbook(new FileInputStream("e:/a.xls"));
Sheet st = wb.getSheetAt(0);
for (int i = 1; i <= st.getLastRowNum(); i++) {
Row row = st.getRow(i);
Contacts con = new Contacts();
System.out.println(row.getLastCellNum());
String[] str = new String[row.getLastCellNum()];
for (int j = 0; j < row.getLastCellNum(); j++) {
Cell cell = row.getCell(j);
if(cell != null) {
str[j] = cell.getStringCellValue();
}
}
con.setName(str[0]);
con.setCompanyname(str[1]);
con.setWeibo(str[2]);
con.setWeibotype(str[3]);
con.setContent(str[4]);
con.setView(str[5]);
con.setAddress(str[6]);
con.setCreatetime(str[7]);
Map<String,Object> map = ActionContext.getContext().getSession();
User user = (User)map.get("user");
con.setUser(user);
con.setEnable(true);
contactsService.save(con);
String[] str2 = str[8].split(",");
Set<Tel> telSet = new HashSet<Tel>();
for (int j = 0; j < str2.length; j++) {
Tel tel = new Tel();
tel.setTel(str2[j]);
tel.setCreatetime(TimeUtil.getTime());
Contacts cs = contactsService.findA(con.getId());
tel.setContacts(cs);
telService.save(tel);
telSet.add(tel);
}
String[] str3 = str[9].split(",");
Set<Im> imSet = new HashSet<Im>();
for (int j = 0; j < str3.length; j++) {
Im im = new Im();
im.setIm(str3[j]);
im.setCreatetime(TimeUtil.getTime());
Contacts cs = contactsService.findA(con.getId());
im.setContacts(cs);
imService.save(im);
imSet.add(im);
}
String[] str4 = str[10].split(",");
Set<Mail> mailSet = new HashSet<Mail>();
for (int j = 0; j < str4.length; j++) {
Mail mail = new Mail();
mail.setMail(str4[j]);
mail.setCreatetime(TimeUtil.getTime());
Contacts cs = contactsService.findA(con.getId());
mail.setContacts(cs);
mailService.save(mail);
mailSet.add(mail);
}
String[] str5 = str[11].split(",");
Set<Website> websiteSet = new HashSet<Website>();
for (int j = 0; j < str5.length; j++) {
Website website = new Website();
website.setCreatetime(TimeUtil.getTime());
website.setWebsite(str5[j]);
Contacts cs = contactsService.findA(con.getId());
website.setContacts(cs);
websiteService.save(website);
websiteSet.add(website);
}
Message message = new Message();
message.setContent(con.getContent());
if (con.getName()==null) {
String title =con.getCompanyname()+","+"addcontactsnote.action?id="+con.getId();
message.setTitle(title);
} else {
String title =con.getName()+" "+con.getCompanyname()+","+"addcontactsnote.action?id="+con.getId();
message.setTitle(title);
}
message.setCreatetime(TimeUtil.getTime());
String type = "联系人"+","+"5FBEEE";
message.setType(type);
message.setUser(user);
message.setView("all");
message.setCtdid(con.getId());
message.setEnable(true);
messageService.save(message);
}
return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
return ERROR;
}
}