导入导出Outlook地址薄

1.导出
从Outlook选择文本模式导出的地址薄是以”,”分割的,而且大部分导出的地址薄也都是以”,”分割的,这样就可以用String类的split方法,主要的源代码:
[java]
BufferedReader bufReader = new BufferedReader(new InputStreamReader(importFile.getInputStream()));
//BufferedReader bufReader = new BufferedReader(new FileReader(filepath));
String header = bufReader.readLine();
String[] attributes = header.split(split);
String line;
while((line = bufReader.readLine()) != null) {
String[] addressAttributes = line.split(split);
int size = addressAttributes.length;
WdxcAddressbook addbook = new WdxcAddressbook();
for(int i = 0;i < attributes.length;i++) {
if(attributes[i].equalsIgnoreCase(“Name”) || attributes[i].equalsIgnoreCase(“姓名”)) {
if(i < size) {
addbook.setRealname(addressAttributes[i]);
continue;
}
else {
break;
}
}
}
}
bufReader.close();
[/java]

2.导出
导出成Excel格式:
[java]
ExternalContext context =
FacesContext.getCurrentInstance().getExternalContext();
HttpServletResponse response = (HttpServletResponse)context.getResponse();
response.addHeader(“Content-Disposition”,”attachment;filename=wdxcaddressbook.xls”);
response.setCharacterEncoding(“GB2312”);
response.setContentType(“application/ms-excel”);
try {
//PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(“E:addressbook.xls”)));
PrintWriter pw = response.getWriter();
pw.println(“Name” + “t” + “E-mail Address” + “t” + “Mobile Phone” + “t” + “Home Phone” + “t” + “Company” + “t” + “Home Street” + “t” + “Home Postal Code” + “t” + “Personal Web Page” + “t” + “Notes”);
List list = addressbookService.getAddressbookByOwnerAndEmail(this.getPrinciple().getUserid(),null);
for(int i = 0;i < list.size();i++) {
WdxcAddressbook address = (WdxcAddressbook)list.get(i);
pw.print(address.getRealname());
pw.print(“t”);
pw.print(address.getEmail());
pw.print(“t”);
}
}catch()
pw.close();
[/java]

3.存在的问题
但导出的Outlook地址薄是以”,”分割的,如果自己有在地址中有”,”,Outlook会自动在这个字段两端添加”””,所有光用split会有点问题的

发表评论

邮箱地址不会被公开。