通过pyinstaller xx.py可以把本源代码编译成xx.exe,但在64位的系统编译成xx.exe的程序在32位的操作系统运行不了。

# coding=utf-8
from Tkinter import *
from tkFileDialog import *
from openpyxl import Workbook
from openpyxl import load_workbook
from openpyxl.styles import Border, Side, Font, Alignment  # 设置字体和边框需要的模块
#from docx import Document
#from docx.shared import Pt
#from docx.shared import Inches
#from docx.oxml.ns import qn
#from docx.enum.text import WD_ALIGN_PARAGRAPH  # 段落居中
import random #
import os
import sys
#import xlrd #读excel要用到xlrd模块
#import xlwt #写excel表要用到xlwt模块
from datetime import datetime
#from xlrd import xldate_as_tuple
import time
from copy import copyclass App:def __init__(self, root):frame = Frame(root)  # containerframe.pack()self.button1 = Button(frame, text="高危集团预警取数基础表", command=self.filefound1, width=20, height=1).grid(row=0, column=0)# self.button1.pack()self.button4 = Button(frame, text="运行", command=self.execuate, width=20, height=1).grid(row=3)# self.button3.pack()self.button5 = Button(frame, text="退出", command=frame.quit, width=20, height=1).grid(row=4)# self.button4.pack()self.e = Entry(frame)self.e.grid(row=0, column=2)self.e.delete(0, END)  # 将输入框里面的内容清空self.e.insert(0, '显示文件路径')self.filepath1 = StringVar()def filefound1(self):self.filepath1 = askopenfilename()print self.filepath1self.e.delete(0, END)  # 将输入框里面的内容清空self.e.insert(0, self.filepath1)return self.filepath1def filefound2(self):self.filepath2 = askopenfilename()print self.filepath2self.e1.delete(0, END)  # 将输入框里面的内容清空self.e1.insert(0, self.filepath2)return self.filepath2def filefound3(self):self.filepath3 = askopenfilename()print self.filepath3self.e2.delete(0, END)  # 将输入框里面的内容清空self.e2.insert(0, self.filepath3)return self.filepath3def set_style(self, name, height, bold=False):  # 一个name参数,一个高度参数,默认不加粗style = xlwt.XFStyle()  # 初始化样式font = xlwt.Font()  # 为样式创建字体font.name = name  # 'Times New Roman'font.bold = bold  # 加粗font.color_index = 4  # 颜色font.height = height  # 高度borders = xlwt.Borders()  # 边框borders.left = 1  # 上下左右borders.right = 1borders.top = 1borders.bottom = 1style.font = font  # 定义字体属性style.borders = borders  # 定义边框属性return styledef Month_of_extraction(self,xlsx_date):  # 提取xlsx文件的月份数Month = ''if type(xlsx_date).__name__=="unicode":XHXC_time = xlsx_dateelse:XHXC_time = xlsx_date.strftime("%Y-%m-%d")if '/' in XHXC_time:Month = XHXC_time.split('/')[1]elif '-' in XHXC_time:Month = XHXC_time.split('-')[1]        #print Month,type(xlsx_date),xlsx_datereturn Monthdef Current_Month_of_extraction(self):  # 提取xlsx文件的月份数XHXC_time = datetime.now().strftime("%Y-%m-%d")          Month = XHXC_time.split('-')[1]        return Monthdef execuate(self):# 配置字体格式为:样式(Times New Roman)、尺寸(11)、斜体(flase)、颜色(黑色)、粗体(flase),这里可以根据自己需求修改font_style = Font(name='Times New Roman', size=11, italic=False, color='FF000000', bold=False)#print self.filepath1, self.filepath2wb_alarm = load_workbook(self.filepath1, data_only=True)len_filepath1 = len(self.filepath1)for i in range(len_filepath1 - 1, -1, -1):if (self.filepath1[i] == '/'):breakmother_path = u""for j in range(0, i + 1):mother_path += self.filepath1[j]model_path = mother_path + u'基础数据//携转预警智慧平台数据统计表模板.xlsx'wb_test = load_workbook(model_path, data_only=True)    # 读取模板清单sheet_test = wb_test.get_sheet_by_name(u'ZMB',)  # 所有集团清单sheet_YSZB  = wb_alarm.get_sheet_by_name(u'YSZB',)  # 西湖集团全量清单sheet_XHJT = wb_alarm.get_sheet_by_name(u'XHJT',)  # 西湖集团全量清单sheet_YKJT = wb_alarm.get_sheet_by_name(u'YKJT',)  # 西湖集团全量清单sheet_XHXC = wb_alarm.get_sheet_by_name(u'XHXC',)  # 西湖携出汇总清单alarm_group_manager_dict = {u'':[u'',u'',u'']} #预警中集团与客户经理和区域的映射
################################################################################ws = wb_test.get_sheet_by_name(wb_test.get_sheet_names()[0]) # # 读取模板清单wb_new = Workbook()ws_new = wb_new.active     #获取第一个sheetws_new.title = u'统计'    #设定一个sheet的名字ws2_new = wb_new.create_sheet("Mysheet", 1)      #设定sheet的插入位置 默认插在后面ws2_new.title = u"20人以上集团详情"    #设定一个sheet的名字 必须是Unicodews3_new = wb_new.create_sheet("Mysheet", 2)      #设定sheet的插入位置 默认插在后面ws3_new.title = u"要客20人以上集团详情"    #设定一个sheet的名字 必须是Unicodemax_row=ws.max_row#最大行数max_column=ws.max_column#最大列数for i in range(1, sheet_XHJT.max_row+1):  # 建立集团与客户经理和区域的字典对应关系    %%%%集团编号,集团客户经理,区域,集团级别,铁通对应分局for j in range(1, 15):ws_new.cell(i, j).value = sheet_test.cell(i, j).value# bold=True加粗# ws_new.cell(i, j).font = Font(name='微软雅黑', size=14, bold=True) wm=zip(ws.merged_cells)#开始处理合并单元格if len(wm)>0:for i in range(0,len(wm)):#cell2=str(wm[i]).replace('(<CellRange','').replace('>,)','') #(<CellRange A1:N1>,)#print str(wm[i]),cell2#cell2 = str(wm[i])[12:]cell2=str(wm[i]).split(' ')[1][:-3]print("MergeCell:%s"%cell2)ws_new.merge_cells(cell2)printout = 0row_xc = 40for m in range(1,max_row+1):ws_new.row_dimensions[m].height=ws.row_dimensions[m].heightfor n in range(1,1+max_column):if n<27:c=chr(n+64).upper()#ASCII字符,chr(65)='A'else:if n<677:c=chr(divmod(n,26)[0]+64)+chr(divmod(n,26)[1]+64)else:c=chr(divmod(n,676)[0]+64)+chr(divmod(divmod(n,676)[1],26)[0]+64)+chr(divmod(divmod(n,676)[1],26)[1]+64)i='%s%d'%(c,m)#单元格编号if m==1:#print("Modifycolumn%swidthfrom%dto%d"%(n,ws_new.column_dimensions[c].width,ws.column_dimensions[c].width))ws_new.column_dimensions[c].width=ws.column_dimensions[c].widthtry:getattr(ws.cell(row=m,column=c),"value")cell1=ws[i]#获取data单元格数据ws_new[i].value=cell1.value#赋值到ws_new单元格if cell1.has_style:#拷贝格式ws_new[i].font=copy(cell1.font)ws_new[i].border=copy(cell1.border)ws_new[i].fill=copy(cell1.fill)ws_new[i].number_format=copy(cell1.number_format)ws_new[i].protection=copy(cell1.protection)ws_new[i].alignment=copy(cell1.alignment)except AttributeError as e:if printout == 0:print("cell(%s)is%s"%(i,e))printout+=1continue
#######################################################################################group_manager_dict = {u'':[u'',u'',u'',u'',u'']} #集团与客户经理和区域的映射YKJT_group_manager_dict = {u'':[u'',u'',u'',u'']} #要客集团与客户经理和区域的映射print('sheet_XHJT.max_row = ',sheet_XHJT.max_row)print u'读取-西湖分公司全量集团表(有对应客户经理、分局).xlsx中…………'for i in range(2, sheet_XHJT.max_row+1):  # 建立集团与客户经理和区域的字典对应关系    %%%%集团编号,集团客户经理,区域,集团级别,铁通对应分局,GROUP_NAMEgroup_manager_dict[sheet_XHJT.cell(i, 1).value] = [sheet_XHJT.cell(i, 7).value,sheet_XHJT.cell(i, 9).value,sheet_XHJT.cell(i, 4).value,sheet_XHJT.cell(i, 10).value,sheet_XHJT.cell(i, 2).value]#print(sheet_XHJT.cell(i, 1).value,':',sheet_XHJT.cell(i, 3).value,':',sheet_XHJT.cell(i, 9).value)if i % 2000 == 0:print '  ',round(1.0*i/(1.0*sheet_XHJT.max_row)*100,2),'%'sheet_YKJTprint('sheet_YKJT.max_row = ',sheet_YKJT.max_row)for i in range(2, sheet_YKJT.max_row+1):  # 建立集团与客户经理和区域的字典对应关系    ##YKJT_group_manager_dict集团编号,集团客户经理,区域,集团级别,集团状态YKJT_group_manager_dict[sheet_YKJT.cell(i, 1).value] = [sheet_YKJT.cell(i, 4).value,sheet_YKJT.cell(i, 16).value,sheet_YKJT.cell(i, 7).value,sheet_YKJT.cell(i, 10).value,sheet_YKJT.cell(i, 2).value]#print(sheet_XHJT.cell(i, 1).value,':',sheet_XHJT.cell(i, 3).value,':',sheet_XHJT.cell(i, 9).value)if i % 2000 == 0:print '  ',round(1.0*i/(1.0*sheet_YKJT.max_row)*100,2),'%'xicheng_YSZB  = [0,0,set(),set(),set(),0,0,0,0,0]xizi_YSZB     = [0,0,set(),set(),set(),0,0,0,0,0]sandun_YSZB   = [0,0,set(),set(),set(),0,0,0,0,0]liuxia_YSZB   = [0,0,set(),set(),set(),0,0,0,0,0]zhijiang_YSZB = [0,0,set(),set(),set(),0,0,0,0,0]hangye_YSZB   = [0,0,set(),set(),set(),0,0,0,0,0]tietong_YSZB  = [0,0,set(),set(),set(),0,0,0,0,0]xiaoyuan_YSZB = [0,0,set(),set(),set(),0,0,0,0,0]qita_YSZB     = [0,0,set(),set(),set(),0,0,0,0,0]yaoke_YSZB    = [0,0,set(),set(),set(),0,0,0,0,0]total_YSZB    = [0,0,0,0,0,0,0,0,0,0]xicheng_tietong  = [0,0,set(),set(),set(),0,0,0,0,0]xizi_tietong     = [0,0,set(),set(),set(),0,0,0,0,0]sandun_tietong   = [0,0,set(),set(),set(),0,0,0,0,0]liuxia_tietong   = [0,0,set(),set(),set(),0,0,0,0,0]zhijiang_tietong = [0,0,set(),set(),set(),0,0,0,0,0]total_tietong    = [0,0,0,0,0,0,0,0,0,0]xicheng_yaoke  = [0,0,set(),set(),set(),0,0,0,0,0]xizi_yaoke     = [0,0,set(),set(),set(),0,0,0,0,0]sandun_yaoke   = [0,0,set(),set(),set(),0,0,0,0,0]liuxia_yaoke   = [0,0,set(),set(),set(),0,0,0,0,0]zhijiang_yaoke = [0,0,set(),set(),set(),0,0,0,0,0]qita_yaoke = [0,0,set(),set(),set(),0,0,0,0,0]total_yaoke    = [0,0,0,0,0,0,0,0,0,0]print('sheet_YSZB.max_row = ',sheet_YSZB.max_row)alarm_groupID_NUM_dict = {0:0} #预警中GROUP_ID与个数的映射  ##统计每个GROUP_ID有多少人要携转alarm_groupID_tietong_NUM_dict = {0:0} #预警中铁通GROUP_ID与个数的映射  ##统计每个GROUP_ID有多少人要携转alarm_groupID_yaoke_NUM_dict = {0:0} #预警中要客GROUP_ID与个数的映射  ##统计每个GROUP_ID有多少人要携转CODE_USER_ID_SET = set()keys_in = 0print u'……………………处理XC查询有号码中……………………'for i in range(2, sheet_YSZB.max_row+1):  # 处理XC查询有号码    集团与客户经理和区域的字典对应关系 %% GROUP_ID ,集团级别,GROUP_NAMEGroup_level = sheet_YSZB.cell(i, 39).value  #YSZB第三十九列GROUP_ID = sheet_YSZB.cell(i, 35).value   #YSZB第三十五列GROUP_NAME = sheet_YSZB.cell(i, 36).value   #YSZB第三十六列PHONE_num = sheet_YSZB.cell(i, 30).value  #YSZB第三十列SANLEI_Members = sheet_YSZB.cell(i, 40).value  #YSZB第四十列GROUP_COUNTY_NAME = sheet_YSZB.cell(i, 41).value  #YSZB第四十一列  有要客标记CODE_USER_ID = sheet_YSZB.cell(i, 30).value  #YSZB第三十列 用户编号if CODE_USER_ID not in CODE_USER_ID_SET:   #用户数剔除,只计算第一个CODE_USER_ID_SET.add(CODE_USER_ID)else:continue   alarm_group_manager_dict[GROUP_ID] = [Group_level,GROUP_NAME,Group_level]if i % 500 == 0:print '  ',round(1.0*i/(1.0*sheet_YSZB.max_row)*100,2),'%'##统计每个GROUP_ID有多少人要携转if  alarm_groupID_yaoke_NUM_dict.has_key(GROUP_ID):##统计每个GROUP_ID有多少人要携转alarm_groupID_yaoke_NUM_dict[GROUP_ID] += 1else:alarm_groupID_yaoke_NUM_dict[GROUP_ID] = 1    ##统计每个GROUP_ID有多少人要携转##统计要客每个GROUP_ID有多少人要携转if alarm_groupID_NUM_dict.has_key(GROUP_ID):##统计每个GROUP_ID有多少人要携转alarm_groupID_NUM_dict[GROUP_ID] += 1else:alarm_groupID_NUM_dict[GROUP_ID] = 1    ##统计每个GROUP_ID有多少人要携转if group_manager_dict.has_key(GROUP_ID):keys_in += 1if group_manager_dict[GROUP_ID][1] ==u'西城':  #0成员累计查询xicheng_YSZB[0] += 1xicheng_YSZB[2].add(GROUP_ID)      #2成员累计查询        if Group_level is not None and('A' in Group_level or 'B' in Group_level):#3其中AB类 xicheng_YSZB[3].add(GROUP_ID)   else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ):#4其中C-F xicheng_YSZB[4].add(GROUP_ID)      if SANLEI_Members  != u'集团普通成员':#5统计三类成员xicheng_YSZB[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num): #6#1390571成员数xicheng_YSZB[6] += 1elif group_manager_dict[GROUP_ID][1] ==u'西子':  #0成员累计查询xizi_YSZB[0] += 1xizi_YSZB[2].add(GROUP_ID)      #2成员累计查询        if Group_level is not None and('A' in Group_level or 'B' in Group_level): #3其中AB类 xizi_YSZB[3].add(GROUP_ID)else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ): #4其中C-F xizi_YSZB[4].add(GROUP_ID)if SANLEI_Members  != u'集团普通成员': #5统计三类成员xizi_YSZB[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num):  #6#1390571成员数xizi_YSZB[6] += 1elif group_manager_dict[GROUP_ID][1] ==u'三墩':  #0成员累计查询sandun_YSZB[0] += 1sandun_YSZB[2].add(GROUP_ID)      #2成员累计查询        if Group_level is not None and('A' in Group_level or 'B' in Group_level): #3其中AB类 sandun_YSZB[3].add(GROUP_ID)else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ): #4其中C-F sandun_YSZB[4].add(GROUP_ID)if SANLEI_Members  != u'集团普通成员': #5统计三类成员sandun_YSZB[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num):  #6#1390571成员数sandun_YSZB[6] += 1elif group_manager_dict[GROUP_ID][1] ==u'留下':  #0成员累计查询liuxia_YSZB[0] += 1liuxia_YSZB[2].add(GROUP_ID)      #2成员累计查询        if Group_level is not None and('A' in Group_level or 'B' in Group_level): #3其中AB类 liuxia_YSZB[3].add(GROUP_ID)else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ): #4其中C-F liuxia_YSZB[4].add(GROUP_ID)if SANLEI_Members  != u'集团普通成员': #5统计三类成员liuxia_YSZB[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num):  #6#1390571成员数liuxia_YSZB[6] += 1elif group_manager_dict[GROUP_ID][1] ==u'之江':  #0成员累计查询zhijiang_YSZB[0] += 1zhijiang_YSZB[2].add(GROUP_ID)      #2成员累计查询        if Group_level is not None and('A' in Group_level or 'B' in Group_level): #3其中AB类 zhijiang_YSZB[3].add(GROUP_ID)else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ): #4其中C-F zhijiang_YSZB[4].add(GROUP_ID)if SANLEI_Members  != u'集团普通成员': #5统计三类成员zhijiang_YSZB[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num):  #6#1390571成员数zhijiang_YSZB[6] += 1elif group_manager_dict[GROUP_ID][1] ==u'行业':  #0成员累计查询hangye_YSZB[0] += 1hangye_YSZB[2].add(GROUP_ID)      #2成员累计查询        if Group_level is not None and('A' in Group_level or 'B' in Group_level): #3其中AB类 hangye_YSZB[3].add(GROUP_ID)else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ): #4其中C-F hangye_YSZB[4].add(GROUP_ID)if SANLEI_Members  != u'集团普通成员': #5统计三类成员hangye_YSZB[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num):  #6#1390571成员数hangye_YSZB[6] += 1elif group_manager_dict[GROUP_ID][1] ==u'校园':  #0成员累计查询xiaoyuan_YSZB[0] += 1xiaoyuan_YSZB[2].add(GROUP_ID)      #2成员累计查询        if Group_level is not None and('A' in Group_level or 'B' in Group_level): #3其中AB类 xiaoyuan_YSZB[3].add(GROUP_ID)else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ): #4其中C-F xiaoyuan_YSZB[4].add(GROUP_ID)if SANLEI_Members  != u'集团普通成员': #5统计三类成员xiaoyuan_YSZB[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num):  #6#1390571成员数xiaoyuan_YSZB[6] += 1elif group_manager_dict[GROUP_ID][1] ==u'铁通':  #0成员累计查询tietong_YSZB[0] += 1tietong_YSZB[2].add(GROUP_ID)      #2成员累计查询        if Group_level is not None and('A' in Group_level or 'B' in Group_level): #3其中AB类 tietong_YSZB[3].add(GROUP_ID)else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ): #4其中C-F tietong_YSZB[4].add(GROUP_ID)if SANLEI_Members  != u'集团普通成员': #5统计三类成员tietong_YSZB[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num):  #6#1390571成员数tietong_YSZB[6] += 1##统计铁通每个GROUP_ID有多少人要携转if alarm_groupID_tietong_NUM_dict.has_key(GROUP_ID):##2统计铁通每个GROUP_ID有多少人要携转alarm_groupID_tietong_NUM_dict[GROUP_ID] += 1else:alarm_groupID_tietong_NUM_dict[GROUP_ID] = 1  ##2统计铁通每个GROUP_ID有多少人要携转Tietong_Area = group_manager_dict[GROUP_ID][3]   #铁通对应区域查询if Tietong_Area==u'西城': #0成员累计查询xicheng_tietong[0]+=1xicheng_tietong[2].add(GROUP_ID)   #2成员累计查询if Group_level is not None and('A' in Group_level or 'B' in Group_level): #3其中AB类 xicheng_tietong[3].add(GROUP_ID)else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ): #4其中C-F xicheng_tietong[4].add(GROUP_ID)if SANLEI_Members  != u'集团普通成员': #5统计三类成员xicheng_tietong[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num):  #6#1390571成员数xicheng_tietong[6] += 1elif Tietong_Area==u'西子': #0成员累计查询xizi_tietong[0]+=1xizi_tietong[2].add(GROUP_ID)   #2成员累计查询if Group_level is not None and('A' in Group_level or 'B' in Group_level): #3其中AB类 xizi_tietong[3].add(GROUP_ID)else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ): #4其中C-F xizi_tietong[4].add(GROUP_ID)if SANLEI_Members  != u'集团普通成员': #5统计三类成员xizi_tietong[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num):  #6#1390571成员数xizi_tietong[6] += 1elif Tietong_Area==u'三墩': #0成员累计查询sandun_tietong[0]+=1sandun_tietong[2].add(GROUP_ID)   #2成员累计查询if Group_level is not None and('A' in Group_level or 'B' in Group_level): #3其中AB类 sandun_tietong[3].add(GROUP_ID)else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ): #4其中C-F sandun_tietong[4].add(GROUP_ID)if SANLEI_Members  != u'集团普通成员': #5统计三类成员sandun_tietong[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num):  #6#1390571成员数sandun_tietong[6] += 1elif Tietong_Area==u'留下': #0成员累计查询liuxia_tietong[0]+=1liuxia_tietong[2].add(GROUP_ID)   #2成员累计查询if Group_level is not None and('A' in Group_level or 'B' in Group_level): #3其中AB类 liuxia_tietong[3].add(GROUP_ID)else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ): #4其中C-F liuxia_tietong[4].add(GROUP_ID)if SANLEI_Members  != u'集团普通成员': #5统计三类成员liuxia_tietong[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num):  #6#1390571成员数liuxia_tietong[6] += 1elif Tietong_Area==u'之江': #0成员累计查询zhijiang_tietong[0]+=1zhijiang_tietong[2].add(GROUP_ID)   #2成员累计查询if Group_level is not None and('A' in Group_level or 'B' in Group_level): #3其中AB类 zhijiang_tietong[3].add(GROUP_ID)else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ): #4其中C-F zhijiang_tietong[4].add(GROUP_ID)if SANLEI_Members  != u'集团普通成员': #5统计三类成员zhijiang_tietong[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num):  #6#1390571成员数zhijiang_tietong[6] += 1elif group_manager_dict[GROUP_ID][1] ==u'要客':  #0成员累计查询yaoke_YSZB[0] += 1yaoke_YSZB[2].add(GROUP_ID)      #2成员累计查询        if Group_level is not None and('A' in Group_level or 'B' in Group_level): #3其中AB类 yaoke_YSZB[3].add(GROUP_ID)else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ): #4其中C-F yaoke_YSZB[4].add(GROUP_ID)if SANLEI_Members  != u'集团普通成员': #5统计三类成员yaoke_YSZB[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num):  #6#1390571成员数yaoke_YSZB[6] += 1else:  #0成员累计查询  其他qita_YSZB[0] += 1qita_YSZB[2].add(GROUP_ID)      #2成员累计查询        if Group_level is not None and('A' in Group_level or 'B' in Group_level): #3其中AB类 qita_YSZB[3].add(GROUP_ID)else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ): #4其中C-F qita_YSZB[4].add(GROUP_ID)if SANLEI_Members  != u'集团普通成员': #5统计三类成员qita_YSZB[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num):  #6#1390571成员数qita_YSZB[6] += 1#要客elif u'08集团' == GROUP_COUNTY_NAME:if YKJT_group_manager_dict.has_key(GROUP_ID): #要客 ##YKJT_group_manager_dict集团编号,集团客户经理,区域,集团级别,集团状态if YKJT_group_manager_dict[GROUP_ID][1] ==u'西城':  #0成员累计查询#要客xicheng_yaoke[0] += 1xicheng_yaoke[2].add(GROUP_ID)      #2成员累计查询        if Group_level is not None and('A' in Group_level or 'B' in Group_level):#3其中AB类 xicheng_yaoke[3].add(GROUP_ID)   else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ):#4其中C-F xicheng_yaoke[4].add(GROUP_ID)      if SANLEI_Members  != u'集团普通成员':#5统计三类成员xicheng_yaoke[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num): #6#1390571成员数xicheng_yaoke[6] += 1     elif YKJT_group_manager_dict[GROUP_ID][1] ==u'西子':  #0成员累计查询#要客xizi_yaoke[0] += 1xizi_yaoke[2].add(GROUP_ID)      #2成员累计查询        if Group_level is not None and('A' in Group_level or 'B' in Group_level):#3其中AB类 xizi_yaoke[3].add(GROUP_ID)   else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ):#4其中C-F xizi_yaoke[4].add(GROUP_ID)      if SANLEI_Members  != u'集团普通成员':#5统计三类成员xizi_yaoke[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num): #6#1390571成员数xizi_yaoke[6] += 1     elif YKJT_group_manager_dict[GROUP_ID][1] ==u'三墩':  #0成员累计查询#要客sandun_yaoke[0] += 1sandun_yaoke[2].add(GROUP_ID)      #2成员累计查询        if Group_level is not None and('A' in Group_level or 'B' in Group_level):#3其中AB类 sandun_yaoke[3].add(GROUP_ID)   else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ):#4其中C-F sandun_yaoke[4].add(GROUP_ID)      if SANLEI_Members  != u'集团普通成员':#5统计三类成员sandun_yaoke[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num): #6#1390571成员数sandun_yaoke[6] += 1     elif YKJT_group_manager_dict[GROUP_ID][1] ==u'留下':  #0成员累计查询#要客liuxia_yaoke[0] += 1liuxia_yaoke[2].add(GROUP_ID)      #2成员累计查询        if Group_level is not None and('A' in Group_level or 'B' in Group_level):#3其中AB类 liuxia_yaoke[3].add(GROUP_ID)   else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ):#4其中C-F liuxia_yaoke[4].add(GROUP_ID)      if SANLEI_Members  != u'集团普通成员':#5统计三类成员liuxia_yaoke[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num): #6#1390571成员数liuxia_yaoke[6] += 1     elif YKJT_group_manager_dict[GROUP_ID][1] ==u'之江':  #0成员累计查询#要客zhijiang_yaoke[0] += 1zhijiang_yaoke[2].add(GROUP_ID)      #2成员累计查询        if Group_level is not None and('A' in Group_level or 'B' in Group_level):#3其中AB类 zhijiang_yaoke[3].add(GROUP_ID)   else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ):#4其中C-F zhijiang_yaoke[4].add(GROUP_ID)      if SANLEI_Members  != u'集团普通成员':#5统计三类成员zhijiang_yaoke[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num): #6#1390571成员数zhijiang_yaoke[6] += 1  else:#其他  #0成员累计查询 #要客zhijiang_yaoke[0] += 1zhijiang_yaoke[2].add(GROUP_ID)      #2成员累计查询        if Group_level is not None and('A' in Group_level or 'B' in Group_level):#3其中AB类 zhijiang_yaoke[3].add(GROUP_ID)   else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ):#4其中C-F zhijiang_yaoke[4].add(GROUP_ID)      if SANLEI_Members  != u'集团普通成员':#5统计三类成员zhijiang_yaoke[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num): #6#1390571成员数zhijiang_yaoke[6] += 1  else: #没有在五个区域内的其他类qita_yaoke[0] += 1qita_yaoke[2].add(GROUP_ID)      #2成员累计查询        if Group_level is not None and('A' in Group_level or 'B' in Group_level):#3其中AB类 qita_yaoke[3].add(GROUP_ID)   else: #elif Group_level is not None and( 'C' in Group_level or 'D' in Group_level or 'E' in Group_level or 'F' in Group_level ):#4其中C-F qita_yaoke[4].add(GROUP_ID)      if SANLEI_Members  != u'集团普通成员':#5统计三类成员qita_yaoke[5] += 1if PHONE_num is not None and '1390571' in str(PHONE_num): #6#1390571成员数qita_yaoke[6] += 1
##########################################################################################print(u'……………………保存YSZB统计结果文件中……………………')                      ##统计累计XC成员大于20集团数#新建"20人以上AB类集团详情"表,保存数据ws2_num=2list_name = [u'集团编号',u'集团名',u'人数',u'客户经理',u'区域',u'集团级别']for i in range(1,len(list_name)+1):ws2_new.cell(1, i).value = list_name[i-1]for key,value in alarm_groupID_NUM_dict.items():if not group_manager_dict.has_key(key):continueif value>=20:ws2_new.cell(ws2_num, 1).value = keyws2_new.cell(ws2_num, 2).value = group_manager_dict[key][4]ws2_new.cell(ws2_num, 3).value = valuews2_new.cell(ws2_num, 4).value = group_manager_dict[key][0]ws2_new.cell(ws2_num, 5).value = group_manager_dict[key][1]ws2_new.cell(ws2_num, 6).value = group_manager_dict[key][2]ws2_new.cell(ws2_num, 7).value = group_manager_dict[key][3]ws2_num+=1if group_manager_dict[key][1] ==u'西城'and value>=20:xicheng_YSZB[1]+=1elif  group_manager_dict[key][1] ==u'西子'and value>=20:xizi_YSZB[1]+=1elif  group_manager_dict[key][1] ==u'三墩'and value>=20:sandun_YSZB[1]+=1elif  group_manager_dict[key][1] ==u'留下'and value>=20:liuxia_YSZB[1]+=1elif  group_manager_dict[key][1] ==u'之江'and value>=20:zhijiang_YSZB[1]+=1elif  group_manager_dict[key][1] ==u'行业'and value>=20:hangye_YSZB[1]+=1elif  group_manager_dict[key][1] ==u'校园'and value>=20:xiaoyuan_YSZB[1]+=1elif  group_manager_dict[key][1] ==u'铁通'and value>=20:tietong_YSZB[1]+=1                   elif value>=20:qita_YSZB[1]+=1print(u'……………………………………YSZB统计数据保存…………………………………………')row_xz = 4for i in range(2, 9):if i==4 or i ==5 or i ==6 :ws_new.cell(row_xz, i).value   = len(xicheng_YSZB[i-2])ws_new.cell(row_xz+1, i).value = len(xizi_YSZB[i-2])ws_new.cell(row_xz+2, i).value = len(sandun_YSZB[i-2])ws_new.cell(row_xz+3, i).value = len(liuxia_YSZB[i-2])ws_new.cell(row_xz+4, i).value = len(zhijiang_YSZB[i-2])ws_new.cell(row_xz+5, i).value = len(hangye_YSZB[i-2])ws_new.cell(row_xz+6, i).value = len(tietong_YSZB[i-2])ws_new.cell(row_xz+7, i).value = len(xiaoyuan_YSZB[i-2])ws_new.cell(row_xz+8, i).value = len(qita_YSZB[i-2])ws_new.cell(row_xz+9, i).value = len(yaoke_YSZB[i-2])total_YSZB[i-2]= len(xicheng_YSZB[i-2])+len(xizi_YSZB[i-2])+len(sandun_YSZB[i-2])+len(liuxia_YSZB[i-2])+len(zhijiang_YSZB[i-2])+len(hangye_YSZB[i-2])+len(tietong_YSZB[i-2])+len(xiaoyuan_YSZB[i-2])+len(yaoke_YSZB[i-2])+len(qita_YSZB[i-2])ws_new.cell(row_xz+10, i).value = total_YSZB[i-2]               else :ws_new.cell(row_xz, i).value   = xicheng_YSZB[i-2]ws_new.cell(row_xz+1, i).value = xizi_YSZB[i-2]ws_new.cell(row_xz+2, i).value = sandun_YSZB[i-2]ws_new.cell(row_xz+3, i).value = liuxia_YSZB[i-2]ws_new.cell(row_xz+4, i).value = zhijiang_YSZB[i-2]ws_new.cell(row_xz+5, i).value = hangye_YSZB[i-2]ws_new.cell(row_xz+6, i).value = tietong_YSZB[i-2]ws_new.cell(row_xz+7, i).value = xiaoyuan_YSZB[i-2]ws_new.cell(row_xz+8, i).value = qita_YSZB[i-2]ws_new.cell(row_xz+9, i).value = yaoke_YSZB[i-2]total_YSZB[i-2]= xicheng_YSZB[i-2]+xizi_YSZB[i-2]+sandun_YSZB[i-2]+liuxia_YSZB[i-2]+zhijiang_YSZB[i-2]+hangye_YSZB[i-2]+tietong_YSZB[i-2]+xiaoyuan_YSZB[i-2]+yaoke_YSZB[i-2]+qita_YSZB[i-2]ws_new.cell(row_xz+10, i).value = total_YSZB[i-2]print(u'……………………………………西湖铁通集团成员XZ高危预警数据保存…………………………………………')
#########################统计 铁通 累计XC成员大于20集团数#######################################ws2_num = 0for key,value in alarm_groupID_tietong_NUM_dict.items():if not group_manager_dict.has_key(key):continueif group_manager_dict[key][1] ==u'西城'and value>=20:xicheng_tietong[1]+=1elif  group_manager_dict[key][1] ==u'西子'and value>=20:xizi_tietong[1]+=1elif  group_manager_dict[key][1] ==u'三墩'and value>=20:sandun_tietong[1]+=1elif  group_manager_dict[key][1] ==u'留下'and value>=20:liuxia_tietong[1]+=1elif  group_manager_dict[key][1] ==u'之江'and value>=20:zhijiang_tietong[1]+=1            row_tt = 18for i in range(2, 9):if i==4 or i ==5 or i ==6 :ws_new.cell(row_tt, i).value   = len(xicheng_tietong[i-2])ws_new.cell(row_tt+1, i).value = len(xizi_tietong[i-2])ws_new.cell(row_tt+2, i).value = len(sandun_tietong[i-2])ws_new.cell(row_tt+3, i).value = len(liuxia_tietong[i-2])ws_new.cell(row_tt+4, i).value = len(zhijiang_tietong[i-2])total_tietong[i-2]= len(xicheng_tietong[i-2])+len(xizi_tietong[i-2])+len(sandun_tietong[i-2])+len(liuxia_tietong[i-2])+len(zhijiang_tietong[i-2])ws_new.cell(row_tt+5, i).value = total_tietong[i-2]               else :ws_new.cell(row_tt, i).value   = xicheng_tietong[i-2]ws_new.cell(row_tt+1, i).value = xizi_tietong[i-2]ws_new.cell(row_tt+2, i).value = sandun_tietong[i-2]ws_new.cell(row_tt+3, i).value = liuxia_tietong[i-2]ws_new.cell(row_tt+4, i).value = zhijiang_tietong[i-2]total_tietong[i-2]= xicheng_tietong[i-2]+xizi_tietong[i-2]+sandun_tietong[i-2]+liuxia_tietong[i-2]+zhijiang_tietong[i-2]ws_new.cell(row_tt+5, i).value = total_tietong[i-2]##########################统计 要客 累计XC成员大于20集团数#######################################print(u'……………………………………西湖要客集团成员XZ高危预警数据保存…………………………………………')ws3_num=2#list_name = [u'集团编号',u'集团名',u'人数',u'客户经理',u'区域',u'集团级别']for i in range(1,len(list_name)+1):ws3_new.cell(1, i).value = list_name[i-1]for key,value in alarm_groupID_yaoke_NUM_dict.items():if not YKJT_group_manager_dict.has_key(key):continueif value>=20:ws3_new.cell(ws3_num, 1).value = keyws3_new.cell(ws3_num, 2).value = YKJT_group_manager_dict[key][4]ws3_new.cell(ws3_num, 3).value = valuews3_new.cell(ws3_num, 4).value = YKJT_group_manager_dict[key][0]ws3_new.cell(ws3_num, 5).value = YKJT_group_manager_dict[key][1]ws3_new.cell(ws3_num, 6).value = YKJT_group_manager_dict[key][2]#ws3_new.cell(ws3_num, 7).value = YKJT_group_manager_dict[key][3]ws3_num+=1if YKJT_group_manager_dict[key][1] ==u'西城'and value>=20:xicheng_yaoke[1]+=1elif  YKJT_group_manager_dict[key][1] ==u'西子'and value>=20:xizi_yaoke[1]+=1elif  YKJT_group_manager_dict[key][1] ==u'三墩'and value>=20:sandun_yaoke[1]+=1elif  YKJT_group_manager_dict[key][1] ==u'留下'and value>=20:liuxia_yaoke[1]+=1elif  YKJT_group_manager_dict[key][1] ==u'之江'and value>=20:zhijiang_yaoke[1]+=1elif value>=20:qita_yaoke[1]+=1row_yk = 28for i in range(2, 9):if i==4 or i ==5 or i ==6 :ws_new.cell(row_yk, i).value   = len(xicheng_yaoke[i-2])ws_new.cell(row_yk+1, i).value = len(xizi_yaoke[i-2])ws_new.cell(row_yk+2, i).value = len(sandun_yaoke[i-2])ws_new.cell(row_yk+3, i).value = len(liuxia_yaoke[i-2])ws_new.cell(row_yk+4, i).value = len(zhijiang_yaoke[i-2])ws_new.cell(row_yk+5, i).value = len(qita_yaoke[i-2])total_yaoke[i-2]= len(xicheng_yaoke[i-2])+len(xizi_yaoke[i-2])+len(sandun_yaoke[i-2])+len(liuxia_yaoke[i-2])+len(zhijiang_yaoke[i-2])+len(qita_yaoke[i-2])ws_new.cell(row_yk+6, i).value = total_yaoke[i-2]               else :ws_new.cell(row_yk, i).value   = xicheng_yaoke[i-2]ws_new.cell(row_yk+1, i).value = xizi_yaoke[i-2]ws_new.cell(row_yk+2, i).value = sandun_yaoke[i-2]ws_new.cell(row_yk+3, i).value = liuxia_yaoke[i-2]ws_new.cell(row_yk+4, i).value = zhijiang_yaoke[i-2]ws_new.cell(row_yk+5, i).value = qita_yaoke[i-2]total_yaoke[i-2]= xicheng_yaoke[i-2]+xizi_yaoke[i-2]+sandun_yaoke[i-2]+liuxia_yaoke[i-2]+zhijiang_yaoke[i-2]+qita_yaoke[i-2]ws_new.cell(row_yk+6, i).value = total_yaoke[i-2]################################################################################################xicheng_XHXC  = [0,0,0,0,set(),set(),0,0,0,0]xizi_XHXC     = [0,0,0,0,set(),set(),0,0,0,0]sandun_XHXC   = [0,0,0,0,set(),set(),0,0,0,0]liuxia_XHXC   = [0,0,0,0,set(),set(),0,0,0,0]zhijiang_XHXC = [0,0,0,0,set(),set(),0,0,0,0]hangye_XHXC   = [0,0,0,0,set(),set(),0,0,0,0]tietong_XHXC  = [0,0,0,0,set(),set(),0,0,0,0]xiaoyuan_XHXC = [0,0,0,0,set(),set(),0,0,0,0]qita_XHXC     = [0,0,0,0,set(),set(),0,0,0,0]total_XHXC    = [0,0,0,0,0,0,0,0,0,0]print('sheet_XHXC.max_row = ',sheet_XHXC.max_row)print u'……………………读取-XHXC清单中……………………'XHXC_groupID_NUM_dict = {u'':0} #预警中GROUP_ID与个数的映射  ##统计每个GROUP_ID有多少人要携转Current_Month = self.Current_Month_of_extraction() # 提取当月的月份数for i in range(2, sheet_XHXC.max_row+1):  # 建立西湖携出清单    %%%%手机号码,集团编号,携出运营商,携出时间PhoneNum = sheet_XHXC.cell(i, 1).valueXHXC_groupID = sheet_XHXC.cell(i, 8).valueOperator = sheet_XHXC.cell(i, 19).valueXHXC_membership_class = sheet_XHXC.cell(i, 11).value #集团级别 AB类XHXC_membership_category = sheet_XHXC.cell(i, 12).value #成员类别 集团普通成员Month = self.Month_of_extraction(sheet_XHXC.cell(i, 7).value)  # 提取xlsx文件的月份数#print PhoneNum,XHXC_groupID,Operator,XHXC_membership_class,Monthif XHXC_groupID_NUM_dict.has_key(XHXC_groupID):##统计每个GROUP_ID有多少人要携转XHXC_groupID_NUM_dict[XHXC_groupID] += 1else:XHXC_groupID_NUM_dict[XHXC_groupID] = 1    ##统计每个GROUP_ID有多少人要携转if group_manager_dict.has_key(XHXC_groupID):#print PhoneNum,XHXC_groupID,Operator,XHXC_membership_class,Monthif group_manager_dict[XHXC_groupID][1] ==u'西城':if Month == Current_Month:#0当月进度,月成员XCxicheng_XHXC[0]  += 1   if XHXC_membership_category  != u'集团普通成员': #1当月进度,三类成员及首号段XCxicheng_XHXC[1] += 1xicheng_XHXC[2]+=1   #2累计成员XCif XHXC_membership_category  != u'集团普通成员' or (PhoneNum is not None and '1390571' in str(PhoneNum)): #3统计三类成员及首号段XC ,##1390571成员数xicheng_XHXC[3] += 1xicheng_XHXC[4].add(XHXC_groupID)  #4累计涉及集团数xicheng_XHXC[5].add(group_manager_dict[XHXC_groupID][0])  #5累计客户经理数if Operator == u'DX':   #6携出电信个数统计xicheng_XHXC[6] += 1elif Operator == u'LT': #7携出联通个数统计xicheng_XHXC[7] += 1xicheng_XHXC[8]  += 1   #8携出联通个数统计elif group_manager_dict[XHXC_groupID][1] ==u'西子':if Month == Current_Month:#0当月进度,月成员XCxizi_XHXC[0]  += 1   if XHXC_membership_category  != u'集团普通成员': #1当月进度,三类成员及首号段XCxizi_XHXC[1] += 1xizi_XHXC[2]+=1   #2累计成员XCif XHXC_membership_category  != u'集团普通成员' or (PhoneNum is not None and '1390571' in str(PhoneNum)): #3统计三类成员及首号段XC ,##1390571成员数xizi_XHXC[3] += 1xizi_XHXC[4].add(XHXC_groupID)  #4累计涉及集团数xizi_XHXC[5].add(group_manager_dict[XHXC_groupID][0])  #5累计客户经理数if Operator == u'DX':   #6携出电信个数统计xizi_XHXC[6] += 1elif Operator == u'LT': #7携出联通个数统计xizi_XHXC[7] += 1xizi_XHXC[8]  += 1   #8携出联通个数统计elif group_manager_dict[XHXC_groupID][1] ==u'三墩':if Month == Current_Month:#0当月进度,月成员XCsandun_XHXC[0]  += 1   if XHXC_membership_category  != u'集团普通成员': #1当月进度,三类成员及首号段XCsandun_XHXC[1] += 1sandun_XHXC[2]+=1   #2累计成员XCif XHXC_membership_category  != u'集团普通成员' or (PhoneNum is not None and '1390571' in str(PhoneNum)): #3统计三类成员及首号段XC ,##1390571成员数sandun_XHXC[3] += 1sandun_XHXC[4].add(XHXC_groupID)  #4累计涉及集团数sandun_XHXC[5].add(group_manager_dict[XHXC_groupID][0])  #5累计客户经理数if Operator == u'DX':   #6携出电信个数统计sandun_XHXC[6] += 1elif Operator == u'LT': #7携出联通个数统计sandun_XHXC[7] += 1sandun_XHXC[8]  += 1   #8携出联通个数统计elif group_manager_dict[XHXC_groupID][1] ==u'留下':if Month == Current_Month:#0当月进度,月成员XCliuxia_XHXC[0]  += 1   if XHXC_membership_category  != u'集团普通成员': #1当月进度,三类成员及首号段XCliuxia_XHXC[1] += 1liuxia_XHXC[2]+=1   #2累计成员XCif XHXC_membership_category  != u'集团普通成员' or (PhoneNum is not None and '1390571' in str(PhoneNum)): #3统计三类成员及首号段XC ,##1390571成员数liuxia_XHXC[3] += 1liuxia_XHXC[4].add(XHXC_groupID)  #4累计涉及集团数liuxia_XHXC[5].add(group_manager_dict[XHXC_groupID][0])  #5累计客户经理数if Operator == u'DX':   #6携出电信个数统计liuxia_XHXC[6] += 1elif Operator == u'LT': #7携出联通个数统计liuxia_XHXC[7] += 1liuxia_XHXC[8]  += 1   #8携出联通个数统计elif group_manager_dict[XHXC_groupID][1] ==u'之江':if Month == Current_Month:#0当月进度,月成员XCzhijiang_XHXC[0]  += 1   if XHXC_membership_category  != u'集团普通成员': #1当月进度,三类成员及首号段XCzhijiang_XHXC[1] += 1zhijiang_XHXC[2]+=1   #2累计成员XCif XHXC_membership_category  != u'集团普通成员' or (PhoneNum is not None and '1390571' in str(PhoneNum)): #3统计三类成员及首号段XC ,##1390571成员数zhijiang_XHXC[3] += 1zhijiang_XHXC[4].add(XHXC_groupID)  #4累计涉及集团数zhijiang_XHXC[5].add(group_manager_dict[XHXC_groupID][0])  #5累计客户经理数if Operator == u'DX':   #6携出电信个数统计zhijiang_XHXC[6] += 1elif Operator == u'LT': #7携出联通个数统计zhijiang_XHXC[7] += 1zhijiang_XHXC[8]  += 1   #8携出联通个数统计elif group_manager_dict[XHXC_groupID][1] ==u'行业':if Month == Current_Month:#0当月进度,月成员XChangye_XHXC[0]  += 1   if XHXC_membership_category  != u'集团普通成员': #1当月进度,三类成员及首号段XChangye_XHXC[1] += 1hangye_XHXC[2]+=1   #2累计成员XCif XHXC_membership_category  != u'集团普通成员' or (PhoneNum is not None and '1390571' in str(PhoneNum)): #3统计三类成员及首号段XC ,##1390571成员数hangye_XHXC[3] += 1hangye_XHXC[4].add(XHXC_groupID)  #4累计涉及集团数hangye_XHXC[5].add(group_manager_dict[XHXC_groupID][0])  #5累计客户经理数if Operator == u'DX':   #6携出电信个数统计hangye_XHXC[6] += 1elif Operator == u'LT': #7携出联通个数统计hangye_XHXC[7] += 1hangye_XHXC[8]  += 1   #8携出联通个数统计elif group_manager_dict[XHXC_groupID][1] ==u'铁通':if Month == Current_Month:#0当月进度,月成员XCtietong_XHXC[0]  += 1   if XHXC_membership_category  != u'集团普通成员': #1当月进度,三类成员及首号段XCtietong_XHXC[1] += 1tietong_XHXC[2]+=1   #2累计成员XCif XHXC_membership_category  != u'集团普通成员' or (PhoneNum is not None and '1390571' in str(PhoneNum)): #3统计三类成员及首号段XC ,##1390571成员数tietong_XHXC[3] += 1tietong_XHXC[4].add(XHXC_groupID)  #4累计涉及集团数tietong_XHXC[5].add(group_manager_dict[XHXC_groupID][0])  #5累计客户经理数if Operator == u'DX':   #6携出电信个数统计tietong_XHXC[6] += 1elif Operator == u'LT': #7携出联通个数统计tietong_XHXC[7] += 1tietong_XHXC[8]  += 1   #8携出联通个数统计elif group_manager_dict[XHXC_groupID][1] ==u'校园':if Month == Current_Month:#0当月进度,月成员XCxiaoyuan_XHXC[0]  += 1   if XHXC_membership_category  != u'集团普通成员': #1当月进度,三类成员及首号段XCxiaoyuan_XHXC[1] += 1xiaoyuan_XHXC[2]+=1   #2累计成员XCif XHXC_membership_category  != u'集团普通成员' or (PhoneNum is not None and '1390571' in str(PhoneNum)): #3统计三类成员及首号段XC ,##1390571成员数xiaoyuan_XHXC[3] += 1xiaoyuan_XHXC[4].add(XHXC_groupID)  #4累计涉及集团数xiaoyuan_XHXC[5].add(group_manager_dict[XHXC_groupID][0])  #5累计客户经理数if Operator == u'DX':   #6携出电信个数统计xiaoyuan_XHXC[6] += 1elif Operator == u'LT': #7携出联通个数统计xiaoyuan_XHXC[7] += 1xiaoyuan_XHXC[8]  += 1   #8携出联通个数统计else:if Month == Current_Month:#0当月进度,月成员XCqita_XHXC[0]  += 1   if XHXC_membership_category  != u'集团普通成员': #1当月进度,三类成员及首号段XCqita_XHXC[1] += 1qita_XHXC[2]+=1   #2累计成员XCif XHXC_membership_category  != u'集团普通成员' or (PhoneNum is not None and '1390571' in str(PhoneNum)): #3统计三类成员及首号段XC ,##1390571成员数qita_XHXC[3] += 1qita_XHXC[4].add(XHXC_groupID)  #4累计涉及集团数qita_XHXC[5].add(group_manager_dict[XHXC_groupID][0])  #5累计客户经理数if Operator == u'DX':   #6携出电信个数统计qita_XHXC[6] += 1elif Operator == u'LT': #7携出联通个数统计qita_XHXC[7] += 1qita_XHXC[8]  += 1   #8携出联通个数统计##########################保存XHXC统计结果文件中##############################print(u'……………………保存XHXC统计结果文件中……………………')##统计累计XC成员大于2集团数for key,value in XHXC_groupID_NUM_dict.items(): if not group_manager_dict.has_key(key):continueif group_manager_dict[key][1] ==u'西城'and value>=2:xicheng_XHXC[9]+=1elif  group_manager_dict[key][1] ==u'西子'and value>=2:xizi_XHXC[9]+=1elif  group_manager_dict[key][1] ==u'三墩'and value>=2:sandun_XHXC[9]+=1elif  group_manager_dict[key][1] ==u'留下'and value>=2:liuxia_XHXC[9]+=1elif  group_manager_dict[key][1] ==u'之江'and value>=2:zhijiang_XHXC[9]+=1elif  group_manager_dict[key][1] ==u'行业'and value>=2:hangye_XHXC[9]+=1elif  group_manager_dict[key][1] ==u'校园'and value>=2:xiaoyuan_XHXC[9]+=1elif  group_manager_dict[key][1] ==u'铁通'and value>=2:tietong_XHXC[9]+=1                   elif value>=2:qita_XHXC[9]+=1for i in range(2, 12):if i==6 or i ==7 :ws_new.cell(row_xc, i).value   = len(xicheng_XHXC[i-2])ws_new.cell(row_xc+1, i).value = len(xizi_XHXC[i-2])ws_new.cell(row_xc+2, i).value = len(sandun_XHXC[i-2])ws_new.cell(row_xc+3, i).value = len(liuxia_XHXC[i-2])ws_new.cell(row_xc+4, i).value = len(zhijiang_XHXC[i-2])ws_new.cell(row_xc+5, i).value = len(hangye_XHXC[i-2])ws_new.cell(row_xc+6, i).value = len(tietong_XHXC[i-2])ws_new.cell(row_xc+7, i).value = len(xiaoyuan_XHXC[i-2])ws_new.cell(row_xc+8, i).value = len(qita_XHXC[i-2])total_XHXC[i-2]= len(xicheng_XHXC[i-2])+len(xizi_XHXC[i-2])+len(sandun_XHXC[i-2])+len(liuxia_XHXC[i-2])+len(zhijiang_XHXC[i-2])+len(hangye_XHXC[i-2])+len(tietong_XHXC[i-2])+len(xiaoyuan_XHXC[i-2])+len(qita_XHXC[i-2])ws_new.cell(row_xc+9, i).value = total_XHXC[i-2]               else :ws_new.cell(row_xc, i).value   = xicheng_XHXC[i-2]ws_new.cell(row_xc+1, i).value = xizi_XHXC[i-2]ws_new.cell(row_xc+2, i).value = sandun_XHXC[i-2]ws_new.cell(row_xc+3, i).value = liuxia_XHXC[i-2]ws_new.cell(row_xc+4, i).value = zhijiang_XHXC[i-2]ws_new.cell(row_xc+5, i).value = hangye_XHXC[i-2]ws_new.cell(row_xc+6, i).value = tietong_XHXC[i-2]ws_new.cell(row_xc+7, i).value = xiaoyuan_XHXC[i-2]ws_new.cell(row_xc+8, i).value = qita_XHXC[i-2]total_XHXC[i-2]= xicheng_XHXC[i-2]+xizi_XHXC[i-2]+sandun_XHXC[i-2]+liuxia_XHXC[i-2]+zhijiang_XHXC[i-2]+hangye_XHXC[i-2]+tietong_XHXC[i-2]+xiaoyuan_XHXC[i-2]+qita_XHXC[i-2]ws_new.cell(row_xc+9, i).value = total_XHXC[i-2]# 提取当前时间local_time = datetime.now()local_str = local_time.strftime('%Y-%m-%d %H-%M-%S')   length = len(self.filepath1)for i in range(length - 1, -1, -1):if (self.filepath1[i] == '/'):breaksavepath1 = u""savepath2 = u""for j in range(0, i + 1):savepath1 += self.filepath1[j]savepath1 = savepath2#print  type(local_str), local_strsavepath1 = savepath1 + u'XZ预警建模统计' + local_str + u'.xlsx'print  u'保存文件为:  ',savepath1wb_new.save(savepath1) # 保存文件########################################################if __name__ == '__main__':root = Tk()root.title('携转分析App')app = App(root)root.mainloop()

Python 读取5张Excel的Sheet自动生成3张Sheet分析结果(减轻同事的工作量,让原本大约2个小时的工作量缩减到1分钟内)相关推荐

  1. python绘制动态图表怎么存下来_用python如何实现导入excel数据后自动生成图表?python如何实现交互式动态图表?...

    这个需求涉及的环节太多了.导入excel文件,获取数据 -- 需要xlrd模块把数据导入python 2. 设定输出图表类型 -- 需要matplot模块.根据数据复杂度,可能需要ETL,那么需要pa ...

  2. Python读取多个excel文件(删除字段、数据格式转换、dataframe多表合并)并写入ElasticSearch实战(自动创建索引、写入ElasticSearch、探索性数据分析)

    Python读取多个excel文件(删除字段.数据格式转换.dataframe多表合并)并写入ElasticSearch实战(自动创建索引.写入ElasticSearch.探索性数据分析) 目录

  3. Python读取和操作Excel(.xlsx)文件

    Python读取和操作Excel(.xlsx)文件 使用openpyxl库来控制excel文件(即.xlsx为后缀的文件).这里介绍一下excel数据的结构. 打开excel文件后生成一个workbo ...

  4. python读取和写入excel里面的数据(附int变float解决方法)

    python读取和写入excel里面的数据(附int变float解决方法) 参考文章: (1)python读取和写入excel里面的数据(附int变float解决方法) (2)https://www. ...

  5. mac如何用python打开excel,Mac——利用Python读取与写入Excel文档

    Mac--利用Python读取与写入Excel文档 目的:按照自定义的格式写入或读取Excel文档,如标红加粗等 Python代码: import xlwt import pandas as pd d ...

  6. Unity编译器 《策划表编表工具》 Excel转Json自动生成解析c#代码

    Unity编译器 <策划表编表工具> Excel转Json自动生成解析c#代码 1.表格数据结构解释 2.Excel文件路径 3.C#代码与Json自动生成路径 点击下载依赖Dll程序集 ...

  7. 电脑表格日期怎么修改原有日期_如何在Excel表中自动生成记录数据的日期和时间...

    几天前有人问我: 在Excel表格中输入信息时,如何在日期单元格中自动生成日期和时间? 输入表格时,我们经常需要输入时间,而不是填写存储时间,为了减少输入工作量,您可以将日期设置为自动生成. 例如,当 ...

  8. python读取多个excel表_python 实现读取一个excel多个sheet表并合并的方法

    python 实现读取一个excel多个sheet表并合并的方法 如下所示: import xlrd import pandas as pd from pandas import DataFrame ...

  9. python读取excel-python读写Excel

    写自动化测试用例的时候需要考虑将 测试数据 和 代码 分离,代码做一层分装,测试数据做统一管理,方便日后维护.这里介绍下测试数据存储在excel,由运行脚本读取的思路. python可以通过 xlrd ...

  10. Python读取和写入excel文件

    Hello!今天我们来聊一下python读取和写入文件的操作. 在进行数据分析和数据挖掘等等有关数据的操作中,我们一般都会碰到python与excel的具体操作.从excel中读取数据出来进行分析,清 ...

最新文章

  1. php怎么实现自动售货,PHP自动化售货发卡网源码+教程
  2. vim编辑器高级应用
  3. jMeter 线程启动时间
  4. 数据管理 - 每天5分钟玩转 Docker 容器技术(147)
  5. java综合案例_综合实例 - Java House - BlogJava
  6. 编写高质量代码的50条黄金守则-Day 03(首选is或as而不是强制类型转换)
  7. php 替换img宽度,php 如何替换img
  8. MySQL高可用--MGR入门(1)单主/多主模式搭建
  9. python读取sas数据集_利用Python获取SAS和R自带数据集
  10. coreldraw铺花纹_详解CorelDRAW位图图样填充
  11. Oracle 19c 安装步骤
  12. 单例模式之懒汉式(三种代码实现)
  13. python自制linux桌面,自己动手写Python实现Ubuntu自动切换壁纸
  14. 卸载程序时遇到“请等待当前程序完成卸载或更改”
  15. 出生年(组成年份的数字种类)
  16. 输入现在的日期,输出明天的日期
  17. Eclipse+ GNU ARM Eclipse Plug-in+ Sourcery G++ Lite Edition for ARM+OPENCD+Jlink的开源开发环境。
  18. c++ http gzip压缩解压缩
  19. 计算机主机能上网玩游戏吗,为什么现在人人都有电脑,还要去网吧玩游戏?
  20. Linux设置软件开机自启动的三种方式(中标麒麟、银河麒麟、ubuntu)

热门文章

  1. 华为交换机关闭网口_华为交换机如何关闭端口号
  2. html 确定取消dialog,弹出一个带确认和取消的dialog实例
  3. java实现计算器_java实现计算器功能
  4. Marlin固件配置教程详解
  5. STM32 之十二 FLASH 使用详解 及 LL 库 FLASH 驱动实现
  6. ESP32 硬件开发指北 -- 外接FLASH使用指北
  7. windows下icns转png或ico
  8. vue页面引用echart的词云图
  9. tableau 日周月筛选器_自定义日期格式
  10. Ubuntu 中文目录改为英文目录