public static void ExportGroupMembers(ObjectId id){
if(session.get("companyid") == null)
login();
Group group = Group.findById(id);
Map<String,Member> members = group.members;
List<User> users = null;
String filterUuid = "contact.uuid in";
if(members!=null){
Set<String> set = members.keySet();
users = User.q().filter("contact <> ", null).filter(filterUuid, set).order("-contact.created").asList();
GenerateFile.generateGroupMember(users,response);
}else {
showMemberList(String.valueOf(id),null);
}
}
//导出代码
public static void generateGroupMember(List<User> users, Response response) {
response.contentType = "text/plain";
String fileName = "";
try {
//fileName = new String(Constant.FILE_NAME_EXPORT_TXT_GROUP_MEMBER.getBytes("UTF-8"), "ISO8859-1");
fileName = URLEncoder.encode(Constant.FILE_NAME_EXPORT_TXT_GROUP_MEMBER, "UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
response.setHeader("Content-Disposition", "attachment; filename="
+ fileName + ".xls");
BufferedOutputStream buff = null;
try {
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
workbook.setSheetName(0,"群组成员信息",(short)1);
HSSFCellStyle style = workbook.createCellStyle();
sheet.setDefaultColumnWidth((short) 14);
HSSFFont font = workbook.createFont();
font.setColor(HSSFColor.BLACK.index);
font.setFontHeightInPoints((short) 12);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
HSSFRow row = sheet.createRow((short)0);
buff = new BufferedOutputStream(response.out);
List<UserContactModel> list = new ArrayList<UserContactModel>();
list = getGroupMemberResultMap(users);
//头部字体样式
style.setFont(font);
//头部字体居中
style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
//头部字体颜色
style.setFillForegroundColor((short) 13);
style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
for (short j = 0; j < Constant.headers.length; j++) {
HSSFCell cell = row.createCell(j);
cell.setEncoding((short) 1);
cell.setCellValue(Constant.headers[j]);
cell.setCellStyle(style);
}
HSSFCellStyle styleCont = workbook.createCellStyle();
styleCont.setAlignment(HSSFCellStyle.ALIGN_LEFT);
//输出内容,外循环控制输出行数
for(int i = 0; i < list.size(); i++){
//创建行获取行元素
HSSFRow rowd = sheet.createRow(i+1);
List<String> datalist = new ArrayList<String>();
datalist.add(list.get(i).getDisplayName());
datalist.add(list.get(i).getPosition());
datalist.add(list.get(i).getImage());
datalist.add(list.get(i).getMobile());
datalist.add(list.get(i).getTel());
datalist.add(list.get(i).getEmils());
datalist.add(list.get(i).getWebsites());
datalist.add(list.get(i).getAddress());
datalist.add(list.get(i).getCompany());
datalist.add(list.get(i).getDepartment());
datalist.add(list.get(i).getIndustry());
datalist.add(list.get(i).getDescription());
datalist.add(list.get(i).getWorkfax());
datalist.add(list.get(i).getPostcode());
//内循环控制每行输出元素
for(short s= 0; s < datalist.size(); s++){
HSSFCell cell = rowd.createCell(s);
cell.setEncoding((short) 1);
cell.setCellValue(datalist.get(s));
cell.setCellStyle(styleCont);
}
}
workbook.write(buff);
buff.flush();
buff.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
buff.flush();
buff.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}