微信企业号通讯录导入

将自己公司OA系统的通讯录导入到微信企业号,可以节省很多的时间。

在批量导入页面,你可以下载标准模板

手工填写?no. 开发人员写一个小程序便可生成符合格式的Excel文件。

【注意】文件必须有表头,表头内容必须和模板一致,即“姓名”,"账号“,输错可不行哦。

部门格式:一级部门/二级部门/三级部门

各级部门用斜杠分隔,同属于多个部门的用分号分隔,如 腾讯公司/微信事业群/企业产品部;腾讯公司/社交事业群/社交媒体产品部,表示

该同事同属于企业产品部和社交媒体产品部。

当组织架构无此部门,则会自动创建部门。

以下为生成标准文件的一段小程序:

 1    /**
 2      * 生成微信企业号批量导入用的表格xlsx  -- http://www.leegtang.com
 3      * @param pb
 4      */
 5     public void writeXls(PageBean pb){
 6         try {
 7             Workbook wb = new XSSFWorkbook();
 8             CreationHelper createHelper = wb.getCreationHelper();
 9             Sheet sheet = wb.createSheet("通讯录wechat-Qy");
10             // Create a row and put some cells in it. Rows are 0 based.
11             
12              
13            // --------- 必须设置表头,否则企业号导入服务无法识别,表头名称必须正确无误 -------------
14            // ---------- 导入后需要重新登录,新加的部门才可见 ,这好像是个bug -----------------
15            Row row = sheet.createRow((short)0);
16             // Create a cell and put a value in it.
17            row.createCell(0).setCellValue("姓名");
18            row.createCell(1).setCellValue("账号");
19            row.createCell(2).setCellValue("性别");
20            row.createCell(3).setCellValue("微信号");
21            row.createCell(4).setCellValue("手机号");
22            row.createCell(5).setCellValue("邮箱");
23            row.createCell(6).setCellValue("所属部门"); 
24            row.createCell(7).setCellValue("职位"); 
25                
26             List lst=pb.getData();
27             int i=1;
28             for (Iterator iterator = lst.iterator(); iterator.hasNext();) {
29                 DingUser object = (DingUser) iterator.next();
30                 System.out.println(object);
31                 
32                    Row row_ = sheet.createRow((short)i);
33                     // Create a cell and put a value in it.
34                    row_.createCell(0).setCellValue(object.getName());
35                    row_.createCell(1).setCellValue(getPingYin(object.getName()));
36                    row_.createCell(2).setCellValue(object.getSex());
37                    row_.createCell(3).setCellValue("");
38                    row_.createCell(4).setCellValue(createHelper.createRichTextString(object.getTel()));
39                    row_.createCell(5).setCellValue("");
40                    row_.createCell(6).setCellValue("B.Team/"+object.getDept()); // B.Team为 最顶级的部门名称,其他部门都在此部门下
41                    row_.createCell(7).setCellValue(object.getTitle()); 
42 
43                    
44                   i++;
45             }
46             
47          
48             String filePath="F:/adoc/wechat-qy.xlsx";
49             FileOutputStream fileOut = new FileOutputStream(filePath);
50             wb.write(fileOut);
51             fileOut.close();
52             System.out.println("########################");
53             System.out.println(filePath+"写入成功!");
54         } catch (Exception e) {
55             e.printStackTrace();
56         }
57     }

更多内容,请到 http://www.leegtang.com

原文地址:https://www.cnblogs.com/leegtang/p/5552267.html