python自动化:uiautomation、pyautogui操作会计记账系统(1)处理三栏明细账

python自动化:uiautomation、pyautogui操作会计记账系统(1)
python处理三栏明细账

#coding=utf-8
import pyautogui, time, pyperclip,pandas,os, uiautomation, subprocess, easygui

pyautogui.PAUSE = 1

#print('当前屏幕分辨率宽 X 高:')
screenWidth, screenHeight = pyautogui.size()
#print(screenWidth, screenHeight) # 屏幕分辨率1920 1080,导出的按钮595,80
# accnt_code_list = ["101", "102", "112", "151", "152", "154", "202", "212", "241", "311", "321", "322", "511", "531",
# "541", "551"]
accnt_code_dict = { "101": "现金", "102": "银行存款", "112": "应收款", "151": "固定资产", "152": "累计折旧", "154": "在建工程", "202": "应付款",
                   "212": "应付福利费", "241": "专项应付款", "311": "公积公益金", "321": "本年收益", "322": "收益分配", "511": "发包及上交收入",
                   "531": "其他收入", "541": "管理费用", "551": "其他支出"}
#accnt_code_list = ["101", "102", "511", "531", "541"]
accnt_code_dict = { "101": "现金", "102": "银行存款", "511": "发包及上交收入","531": "其他收入", "541": "管理费用"}
accnt_code_dict = { "531": "其他收入"}
accnt_code_dict = { "101": "现金", "102": "银行存款", "112": "应收款","202": "应付款",
                   "241": "专项应付款", "511": "发包及上交收入",
                   "531": "其他收入", "541": "管理费用", "551": "其他支出"}
accnt_code_dict = { "101": "现金", "102": "银行存款", "511": "发包及上交收入", "531": "其他收入", "541": "管理费用", "551": "其他支出"}
accnt_code_dict = {  "511": "发包及上交收入", "531": "其他收入"}



choi_save_as = easygui.choicebox(msg='请选择生成的word文档', title='提示', choices=('导出Excel', '导出PDF', '打印'))


def creat_file(year_input):
    print('开始运行创建文件夹自定义函数……')
    with open('**电脑端账套号生成村委会文件夹用.txt', 'r') as f:
        dic = []
        for line in f.readlines():
            line = line.strip('\n')  # 去掉换行符\n
            b = line.split('\t')  # 将每一行以空格为分隔符转换成列表
            #print(list(b))
            dic.append(b)

        #print(dic)
        admin_villi_dict=dict(dic)
        print('账套所在的村委会文件夹列表是:')
        print(admin_villi_dict)#列表转字典
    if not os.path.exists('D:\**会计系统导出数据'):
        os.mkdir('D:\**会计系统导出数据')

    admin_villi_list=['前锋', '西海', '八家', '冲洋', '新围', '竹洛', '竹湖', '新屋', '达材', '朝中', '官窦', '伞塘', '白岗', '稔坪', '西坑', '三和', '居委']

    year = time.strftime("%Y")
    #print("当前年份是:", year)
    if year_input==year:#等于
        time1 = time.strftime("%Y%m%d", time.localtime())  # 加上秒不会出现同名
    else:
        time1= year_input #赋值
    #print('创建第3层文件夹folder3_1')
    folder3_1 = r"D:\**会计系统导出数据" + '\\' + time1 + '三栏明细账'
    #print('判断文件夹是否存在,不存在则创建,文件保存在:'+folder3_1)
    if not os.path.exists(folder3_1):
        os.mkdir(folder3_1)
    #print('创建第4层文件夹folder4_i')
    for i in range(0,16):
        folder_admin_villi=time1+admin_villi_list[i]+'三栏明细账'
        folder4_i=r'D:\**会计系统导出数据'+'\\'+ time1 + '三栏明细账'+'\\' +folder_admin_villi
        if not os.path.exists(folder4_i):
            os.mkdir(folder4_i)
            #print('创建文件夹:'+folder4_i)

    return  admin_villi_dict,folder3_1


def check_file(folder3_1):
    # 打开文件

    path= folder3_1
    dirs = os.listdir(path)
    year = time.strftime("%Y")



    file_accnt_num_list=[]
    for home, dirs, files in os.walk(path):
        for file_name in files:
            #filelist.append(os.path.join(home, file_name))
            if os.path.splitext(file_name)[1] == '.xls':
                #print(file_name)
                file_year = file_name[0:4]  # 截取文件名前4个字符
                #print(file_year)
                # os.rename(file, new) # 进行重命名

                if file_year == year:
                    # 取整方法是可以去除0,但是遇到字符串不能转化为整型会报错
                    # file_accnt_num=int(file_name[9:12])
                    s = file_name[9:12]
                    file_accnt_num = "".join(s[::1]).lstrip("0")
                    #print(file_accnt_num)
                else:
                    s = file_name[5:8]
                    file_accnt_num = "".join(s[::1]).lstrip("0")
                    #print(file_accnt_num)
                file_accnt_num_list.append((file_accnt_num))

    #print(filelist)
    print(file_accnt_num_list)
    #print('对列表进行排序,查找时可能减少遍历次数。也便于根据账套号顺序查找')
    #file_accnt_num_list2=file_accnt_num_list.sort()
    #print('sort影响列表本身,sorted不影响列表本身,用sort排序')
    file_exist_list = sorted(file_accnt_num_list)
    #print('已导出的文件列表','file_exist_list:')
    #print(file_exist_list)
    print('已导出的文件数量',len(file_exist_list))
    return file_exist_list

def accnt_login(account_Num):
    wc1 = uiautomation.WindowControl(searchDepth=1, Name='帐套登陆')
    # 设置为顶层
    #pyautogui.alert(text="按回车键继续程序", title="提示") # 窗口前置才能用键盘快捷键
    wc1.SetTopmost(True)  # 置顶能用快捷键
    pc2_1= wc1.PaneControl(searchDepth=1, Name='帐套信息')
    ec3_8=pc2_1.EditControl(searchDepth=1, Name='', foundIndex=2)
    ec3_8.SetFocus()
    #print('ec3_8')
    #print('账套号输入框的位置是:')
    #print(ec3_8.BoundingRectangle)
    pyperclip.copy(account_Num) #account_Num是账套号
    pyautogui.hotkey('ctrl', 'v')  # 再粘贴
    pyautogui.press('enter')

def user_login():
    wc1=uiautomation.WindowControl(searchDepth=1, Name='用户注册')
    # 设置为顶层
    wc1.SetTopmost(True)  # 置顶能用快捷键
    pyautogui.press('down')  # 向下选择超级用户
    pyautogui.press('enter')  # 点击确定
    pyautogui.press('enter')  # 点击确定
    #print('超级用户登录成功')

def select_year(year_input):
    #print('深度1')
    wc1 = uiautomation.WindowControl(searchDepth=1, Name='**经营管理系统V2007 - [三栏明细帐]')
    # 设置为顶层
    print(wc1.Name)

    #print('深度2') #isum自创字母后的数字表示深度
    pc2 = wc1.PaneControl(searchDepth=1, Name='工作区')
    #print(pc2.Name)

    #print('深度3')
    wc3= pc2.WindowControl(searchDepth=1, Name='三栏明细帐')
    #print(wc3.Name)

    #print('深度4')
    pc4 = wc3.PaneControl(searchDepth=1, ClassName='TPanel', foundIndex=2)
    #print(pc4.Name) #Name: 'Panel6' #搜索的是第一个

    #pc = wc.PaneControl(searchDepth=1, ClassName='TPanel', AutomationId= '9701258') #AutomationId是动态变化的不能用
    pc4 = wc3.PaneControl(searchDepth=1, ClassName='TPanel', Name= '')
    #print(pc4.Name) #Name: 'Panel6' #搜索的是第一个
    #print(pc4.AutomationId)

    #print('深度5')
    pc5_2= pc4.PaneControl(searchDepth=1, ClassName='TPanel', foundIndex=2)
    #print(pc5_2.Name)
    #print(pc5_2.AutomationId)

    pc5_4= pc4.PaneControl(searchDepth=1, ClassName='TPanel', foundIndex=4)
    #print('pc5_4')
    #print(pc5_4.Name)
    #print(pc5_4.AutomationId)

    pc5_5= pc4.PaneControl(searchDepth=1, ClassName='TPanel', foundIndex=5)
    #print('pc5_5')
    #print(pc5_5.Name)
    #print(pc5_5.AutomationId)

    #print('深度6')
    pc6= pc5_2.PaneControl(searchDepth=1, ClassName='TPanel')
    #print('pc6')
    #print(pc6.Name)
    #print(pc6.AutomationId)

    #全部数据上层
    cbc6_1= pc5_4.ComboBoxControl(searchDepth=1,ClassName='TComboBox',foundIndex=2)
    #print('cbc6_1')
    #print(cbc6_1.Name) #
    #print(cbc6_1.AutomationId)
    cbc6_1.Click()
    pyautogui.press('down')
    pyautogui.press('down')

    # #全部数据下层
    # tc7_1=cbc6_1.TextControl(searchDepth=1,Name='')
    # print('tc7_1')
    # print(tc7_1)
    # print(tc7_1.AutomationId)

    ec6_1= pc5_4.EditControl(searchDepth=1, ClassName='TEdit')
    #print('先获取焦点,否则不能写入年份')
    ec6_1.SetFocus()
    #ec6_1.SendKey('2020')不能写入
    pyperclip.copy(year_input)
    pyautogui.hotkey('ctrl', 'v')
    #print(ec6_1.AutomationId)

    #print('深度7')
    pc7= pc6.PaneControl(searchDepth=1, ClassName='TdxCheckbox')
    #print(pc7.Name) #方式二科目范围
    #print(pc7.AutomationId)

def select_accnt_code(accnt_code):
    #print('深度1')
    wc1 = uiautomation.WindowControl(searchDepth=1, Name='**经营管理系统V2007 - [三栏明细帐]')
    # 设置为顶层
    #print(wc1.Name)

    #print('深度2') #isum自创字母后的数字表示深度
    pc2 = wc1.PaneControl(searchDepth=1, Name='工作区')
    #print(pc2.Name)

    #print('深度3')
    wc3= pc2.WindowControl(searchDepth=1, Name='三栏明细帐')
    #print('定位到',end='')
    #print(wc3.Name)


    #print('深度4')
    pc4 = wc3.PaneControl(searchDepth=1, ClassName='TPanel', foundIndex=2)
    #print(pc4.Name) #Name: 'Panel6' #搜索的是第一个

    #pc = wc.PaneControl(searchDepth=1, ClassName='TPanel', AutomationId= '9701258') #AutomationId是动态变化的不能用
    pc4 = wc3.PaneControl(searchDepth=1, ClassName='TPanel', Name= '')
    #print(pc4.Name) #Name: 'Panel6' #搜索的是第一个
    #print(pc4.AutomationId)


    pc5_3= pc4.PaneControl(searchDepth=1, ClassName='TPanel', foundIndex=3)
    #print(pc5_3.Name)
    #print(pc5_3.AutomationId)

    pc6_2= pc5_3.PaneControl(searchDepth=1, ClassName='TPanel')
    #print('pc6_2')
    #print(pc6_2.Name) # Name: '方式一:特定科目'
    #print(pc6_2.AutomationId)

    pc7_2= pc6_2.PaneControl(searchDepth=1, ClassName='TdxCheckbox')
    #print(pc7_2.Name) # Name: '方式一:特定科目'
    #print(pc7_2.AutomationId)
    #pc7_2.SendKey('101') 不能用,因为PaneControl是不能输入值的
    #pc7_2.SetFocus()#不用setfocus也可以的
    time.sleep(2)
    pc7_2.Click()

    time.sleep(1)
    #print('定位到方式一:特定科目,tab建切换到文本输入框。')
    pyautogui.press('tab')
    pyperclip.copy(accnt_code) #101现金科目代码
    pyautogui.hotkey('ctrl', 'v')
    time.sleep(1)
    pyautogui.press('tab')


def to_excel(accnt_code, accnt_Num_name,year_input):

    #time1 =time.strftime("%Y%m%d%H%M%S", time.localtime())#加上秒不会出现同名
    year = time.strftime("%Y")
    print("当前年份是:", year)
    if year_input==year:#等于
        time1 = time.strftime("%Y%m%d", time.localtime())  # 加上秒不会出现同名
    else:
        time1= year_input #赋值
    #file_path= r"D:\**会计系统导出数据"+'\\'+time1+'现金三栏明细账'+'\\'+file_name+'.xls'
    file_path = r"D:\**会计系统导出数据" + '\\' + time1 + '三栏明细账'
    print('判断文件夹是否存在,不存在则创建,文件保存在:'+file_path)
    if not os.path.exists(file_path):
        os.mkdir(file_path)

    file_name = time1 + " " + accnt_Num_name + accnt_code_dict[accnt_code] + "三栏明细账"
    file_title = accnt_code_dict[accnt_code] +"三栏明细账(" + accnt_Num_name + ")"

    # if accnt_code == '101':
    # file_name = time1 + " " + accnt_Num_name + "现金三栏明细账"
    # file_title = "现金三栏明细账(" + accnt_Num_name + ")"
    #
    # print('文件保存路径是:'+file_path)
    #
    # if accnt_code == '102':
    # file_name = time1 + " " + accnt_Num_name + "银行存款三栏明细账"
    # file_title = "银行存款三栏明细账(" + accnt_Num_name + ")"
    # if accnt_code == '531':
    # file_name = time1 + " " + accnt_Num_name + "其他收入三栏明细账"
    # file_title = "其他收入三栏明细账(" + accnt_Num_name + ")"
    file_full_path = file_path + '\\' + file_name + '.xls'
    print("文件名是:",end="")
    print(file_name)
    #pyautogui.typewrite(file_name) #不能写入中文
    wc1 = uiautomation.WindowControl(searchDepth=1, Name='**经营管理系统V2007 - [三栏明细帐]')



    if choi_save_as == '导出Excel': #可以用if choi_save_as == '导出Excel' and not os.path.exists(file_full_path):?
        if not os.path.exists(file_full_path): #如果文件不存在(即未导出)
            # pyautogui.click(470,60) #点击导出
            pyautogui.click(screenWidth / 4.0851, screenHeight / 18)
            time.sleep(0.5)
            # pyautogui.click(590,80) #点击导出
            # time.sleep(1)
            pyautogui.press('down')  # 按向下键,选择导出Excel表格
            time.sleep(0.5)
            pyautogui.press('enter')  # 点击确定
            # pyautogui.click(640,345) #点击桌面,弹出来的对话框位置不断变化的
            # #pyautogui.click(650,475) #点击我的文档
            # pyautogui.click(650,475) #点击文件名输入框
            # #pyautogui.press('backspace')#删除
            pyautogui.keyDown('backspace')  # 长摁删除键
            time.sleep(1)
            pyautogui.keyUp('backspace')
            pyperclip.copy(file_full_path)  # 写入文件名
            pyautogui.hotkey('ctrl', 'v')  # 再粘贴
            pyautogui.press('enter')  # 点击确定
            time.sleep(1)

            wc1.Minimize()  # 最小化缩小窗口
            wc1.SetTopmost(False)
            time.sleep(20)#等待自动打开Excel,必须足够长时间,不然会出现文件名出现不了
            pyautogui.click(screenWidth/1.8113, screenHeight/4.6957) #点击标题,使得WPS前置。(1060,230),Excel的显示方式必须是全屏

            pyautogui.typewrite(" ")
            pyautogui.press('backspace')
            #yautogui.press('insert') #
            pyperclip.copy(file_title)  # 写入表格标题
            pyautogui.hotkey('ctrl', 'v')  # 再粘贴
            time.sleep(0.5)
            pyautogui.hotkey('alt', 'f4')  # 关闭Excel
            time.sleep(0.5)
            pyautogui.press('enter')  # 点击确定,保存更改
            time.sleep(1)
            #这里需要加一个,假如保存文件失败之后,**系统错误提示
            #标题是错误,内容是路径不存在或者文件不可写! 确定。
            #pyautogui.press('enter')
        else:
            print('{}--文件已经存在,不需导出。'.format(file_full_path))
    if choi_save_as == '导出PDF' or choi_save_as == '打印':
        pyautogui.click(screenWidth / 4.5714, screenHeight / 18) #点击(420, 60)
        pyautogui.press('down')  # 按向下键,选择当前科目
        pyautogui.press('enter')  # 点击确定
        time.sleep(2)
        pyautogui.click(screenWidth /16, screenHeight / 30.8571) #点击(120, 35)
        #默认打印机是提前设定好的打印机,输出PDF默认打印机是PDF虚拟打印机。
        pyautogui.press('enter')  # 点击确定打印
        if choi_save_as == '导出PDF' and not (file_path + '\\' + file_name + '.pdf'):
            time.sleep(1)
            pyautogui.keyDown('backspace')  # 长摁删除键
            time.sleep(1)
            pyautogui.keyUp('backspace')
            pyperclip.copy(file_full_path.strip('.xls'))  # 写入文件名
            pyautogui.hotkey('ctrl', 'v')  # 再粘贴,写入文件全路径
            pyautogui.press('enter')  # 点击确定
        time.sleep(3)
        pyautogui.hotkey('alt', 'f4')  # 关闭PDF
    wc1.Restore()#将窗口回复到最大化
    wc1.SetTopmost(True)
    return file_full_path


#另选账套的菜单栏按钮定位方法
def chage_accnt():
    wc1 = uiautomation.WindowControl(searchDepth=1, Name='**经营管理系统V2007 - [三栏明细帐]')
    # 设置为顶层
    #print(wc1.Name)
    wc1.SetActive(True)
    #print('深度2') #simon自创字母后的数字表示深度
    pc2 = wc1.PaneControl(searchDepth=1, Name='工作区')
    #print(pc2.Name)

    mbc2=wc1.MenuBarControl(searchDepth=1, Name= '应用程序')
    #print('mbc2')
    #print(mbc2.Name)

    mic3_9=mbc2.MenuItemControl(searchDepth=1, Name='', foundIndex=9)
    #print('mic3_9')
    #print(mic3_9.BoundingRectangle)#(700,27,788,51)[88x24]
    #print('点击另选账套')
    mic3_9.Click()
    #另选账套的坐标:Rect: (700,27,788,51)
    #这四个 参数 分别代表的意思是: left top right bottom 是 左 上 右 下。



def open_fold():
    # #open folder,打开文件夹,用win+E快捷键
    pyautogui.hotkey('win', 'e')
    pyautogui.press('tab')
    #pyautogui.press('insert')
    pyautogui.press('enter')
    pyperclip.copy('D:\**会计系统导出数据')
    pyautogui.hotkey('ctrl', 'v')
    pyautogui.press('enter')

def func():
    # print('当前屏幕分辨率宽 X 高:')
    # screenWidth, screenHeight = pyautogui.size()
    # print(screenWidth, screenHeight) # 屏幕分辨率1920 1080,导出的按钮595,80

    #df=pandas.read_excel('**电脑端账套号pandas.xlsx')
    msg = '浏览需要导出的村委会Excel表格文件并打开'
    title = '打开文件'
    filePath = easygui.fileopenbox(msg, title)
    print(filePath)
    df = pandas.read_excel(filePath)
    accnt_dict=dict(zip(df['账套号'],df['账套号加单位简称']))

    # # 字典去除空值
    # accnt_dict2 = {}
    # for o in accnt_dict:
    # if not accnt_dict[o] == '':
    # accnt_dict2[o] = accnt_dict[o]
    # print(accnt_dict2)
    # accnt_dict.clear()
    # accnt_dict = accnt_dict2
    # for i in accnt_dict.keys():
    # print(i)
    nrows = df.shape[0]  # 行数


    #account_Num= 42

    #pyautogui.alert(text="桌面
    # 不能打开其他程序,程序在左下角运行。程序运行时不能操作鼠标和键盘。文件保存在D:\**会计系统导出数据",title="提示")
    time.sleep(1)

    #time.sleep(20)

    #打开程序
    proc_list = ['D:\**经营管理系统2007版\BJACCOUNT.EXE', 'E:\**经营管理系统2007版\BJACCOUNT.EXE', 'C:\**经营管理系统2007版\BJACCOUNT.EXE',
                 'F:\**经营管理系统2007版\BJACCOUNT.EXE', 'G:\**经营管理系统2007版\BJACCOUNT.EXE','H:\**经营管理系统2007版\BJACCOUNT.EXE',
                 'I:\**经营管理系统2007版\BJACCOUNT.EXE', 'J:\**经营管理系统2007版\BJACCOUNT.EXE', 'K:\**经营管理系统2007版\BJACCOUNT.EXE',
                 'D:\Program Files\**经营管理系统2007版\BJACCOUNT.EXE', 'E:\Program Files\**经营管理系统2007版\BJACCOUNT.EXE',
                 'C:\Program Files\**经营管理系统2007版\BJACCOUNT.EXE', 'F:\Program Files\**经营管理系统2007版\BJACCOUNT.EXE',
                 'G:\Program Files\**经营管理系统2007版\BJACCOUNT.EXE', 'H:\Program Files\**经营管理系统2007版\BJACCOUNT.EXE',
                 'I:\Program Files\**经营管理系统2007版\BJACCOUNT.EXE', 'J:\Program Files\**经营管理系统2007版\BJACCOUNT.EXE',
                 'K:\Program Files\**经营管理系统2007版\BJACCOUNT.EXE',
                 'D:\Program Files (x86)\**经营管理系统2007版\BJACCOUNT.EXE', 'E:\Program Files (x86)\**经营管理系统2007版\BJACCOUNT.EXE',
                 'C:\Program Files (x86)\**经营管理系统2007版\BJACCOUNT.EXE', 'F:\Program Files (x86)\**经营管理系统2007版\BJACCOUNT.EXE',
                 'G:\Program Files (x86)\**经营管理系统2007版\BJACCOUNT.EXE', 'H:\Program Files (x86)\**经营管理系统2007版\BJACCOUNT.EXE',
                 'I:\Program Files (x86)\**经营管理系统2007版\BJACCOUNT.EXE', 'J:\Program Files (x86)\**经营管理系统2007版\BJACCOUNT.EXE',
                 'K:\Program Files (x86)\**经营管理系统2007版\BJACCOUNT.EXE',
                 ]
    for i in range(len(proc_list)):
        try:
            subprocess.Popen(proc_list[i])
            #print('程序在:{}'.format(proc_list[i]))
            break
        except:
            #print('程序不在:{}'.format(proc_list[i]))
            pass
    time.sleep(2)
    wc = uiautomation.WindowControl(searchDepth=1, Name='帐套登陆')
    # 设置为顶层
    #pyautogui.alert(text="按回车键继续程序", title="提示") # 窗口前置才能用键盘快捷键
    wc.SetTopmost(True)  # 置顶能用快捷键
    year = time.strftime("%Y")
    #print("当前年份是:", year)
    year_input = pyautogui.prompt('请输入账套查询的年份:')
    #print('弹窗输入年份:' + year_input)

    #print('不要把创建文件夹自定义函数放在循环内,先创建文件夹……')
    admin_villi_dict,folder3_1 = creat_file(year_input)
    #print('遍历3级文件夹下所有文件,检查表格上账套号对应的Excel表是否已导出')
    file_exist_list=check_file(folder3_1)

    print('Excel文件上要导出的文件数量及文件列表是:','list_accnt_dict(要先将字典的键转化为字符串格式,两个列表的元素都是字符串才能做减法)')
    list_accnt_dict= [str(t) for t in list(accnt_dict)]
    print(len(list_accnt_dict),list_accnt_dict)



    print('已导出的数量及文件列表', 'file_exist_list:')
    print(len(file_exist_list),file_exist_list)
    #print('删除两个列表重复值,一个列表减去另一个列表,用set(集合)操作')
    accnt_list2=list(set(list_accnt_dict)-set(file_exist_list))
    print(accnt_list2)

    print('sort影响列表本身,sorted不影响列表本身,用sort排序')
    accnt_list2 = sorted(accnt_list2)
    #删除列表中的nan空值
    while 'nan' in accnt_list2:
        accnt_list2.remove('nan')
    print('未导出的文件数量及文件列表是:')
    print(len(accnt_list2), accnt_list2)

    # accnt_Num_txt = wc.EditControl()
    # #print(accnt_Num_txt)
    #


    file_numb = 0
    for i in accnt_list2: #for i in accnt_dict.keys():
        #print('i在之前转化为字符串,要重新转化为数值格式')
        i = int(i)
        #print('直接用遍历字典的键值循环,i就是账套号')
        accnt_Num_name=accnt_dict[i]
        print('账套号是:' + str(i) + ',账套名称是:' + accnt_Num_name)
        time.sleep(1)
        #账套号登录自定义函数
        accnt_login(i)
        time.sleep(1)
        #用户登录自定义函数
        user_login()

        time.sleep(1)#第二次循环时

        # 选项出现较慢,需要等待

        #pyautogui.click(700, 925) # 点击三栏明细账
        pyautogui.click(screenWidth/2.7429, screenHeight/1.1676)


        time.sleep(1)
        #操作三栏明细账自定义函数
        if year_input!=year:
            select_year(year_input)

        # accnt_code = '101'
        # select_accnt_code(accnt_code)
        # time.sleep(1)
        # to_excel(accnt_code, accnt_Num_name,year_input)
        # time.sleep(2)
        # accnt_code = '102'
        # select_accnt_code(accnt_code)
        # time.sleep(1)
        # to_excel(accnt_code, accnt_Num_name,year_input)

        #list(accnt_code_list.keys()把字典的键转化为列表,就可以遍历字典的键了。
        for accnt_code in list(accnt_code_dict.keys()):
        #for accnt_code in accnt_code_list:
            select_accnt_code(accnt_code) #填写科目代码,会弹窗提示: Name: '601科目不存在,系统跳过!'
            time.sleep(1)
            #科目代码不存在时会弹窗
            wc1 = uiautomation.WindowControl(searchDepth=1, Name='**经营管理系统V2007 - [三栏明细帐]')
            # 设置为顶层
            #print(wc1.Name)
            wc1.SetActive(True)
            try:
                #print('深度2') # simon自创字母后的数字表示深度
                wc2_1_1 = wc1.WindowControl(searchDepth=1, Name='提示')
                # print('提示')
                # print(wc2_1_1.Name)
                bc3_1_1 = wc2_1_1.ButtonControl(searchDepth=1, Name='确定')
                #print('bc3_1_1确定')
                #print(bc3_1_1.Name)
                bc3_1_1.SetFocus()
                pyautogui.press('enter') #点击确定
                # pyautogui.keyDown('backspace') # 长摁删除键
                # time.sleep(1)
                # pyautogui.keyUp('backspace')


            except:
                if wc2_1_1.Exists():
                    pass
                else:
                    print('导出Excel表涉及到创建文件夹,创建文件,需要输入屏幕长宽、年份、账套号、账套名称、账套所在村委会字典')
                    file_full_path = to_excel(accnt_code, accnt_Num_name,year_input)
                    time.sleep(4)
        #pyautogui.click(722,37) #另选账套
        #pyautogui.click(600,30) #另选账套
        pyautogui.click(screenWidth/3.2, screenHeight/36)

        #account_Num+=1
        time.sleep(4)#另选账套必须足够长时间,因为窗口切换幅度大
        file_numb+=1
        print('准备导出第{}个文件:'.format(file_numb))
#pyautogui.alert(text=r"文件保存在D:\**会计系统导出数据", title="提示") #
if __name__ == "__main__":
    func()
    open_fold()
    原文作者:weixin_46655338
    原文地址: https://blog.csdn.net/weixin_46655338/article/details/124807084
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞