sunjiali_weixin_33816611的博客-程序员宅基地

技术标签: python  



# coding: utf-8
import tkinter as tk
from ttk import Button


class Main(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.geometry(self.getSize())

        tk.Label(self, height=1).grid(row=0, column=1)
        Button(self, text='钉钉数据', command=self.OpenDingDingFile, width=20).grid(row=1, column=3)
        tk.Label(self, width=15, text='钉钉数据地址:').grid(row=1, column=0)
        self.LB1 = tk.Label(self, width=40,text="")
        self.LB1.grid(row=1, column=1)
        tk.Label(self, width=4).grid(row=1, column=4)
        Button(self, text='考勤数据', command=self.OpenKaoQinFile, width=20).grid(row=2, column=3)
        tk.Label(self, width=15, text='考勤数据地址:').grid(row=2, column=0)
        self.LB2 = tk.Label(self, width=40,text="")
        self.LB2.grid(row=2, column=1)
        Button(self, text='合并', command=self.getResult, width=20).grid(row=3, column=3)
        tk.Label(self, height=3).grid(row=4, column=2)
        self.return_msg = tk.Label(self, text="")
        self.return_msg.grid(row=4, column=0, columnspan=4)

    def getSize(self):
        """
        :description: 获取窗口的大小
        :return: 返回需要的大小
        """
        curWidth = 600
        curHeight = 200
        scnWidth, scnHeight = self.maxsize()
        tmpcnf = '%dx%d+%d+%d' % (curWidth, curHeight,
                                  (scnWidth - curWidth) / 2, (scnHeight - curHeight) / 2 - 150)
        return tmpcnf

    def OpenKaoQinFile(self):
        pass

    def OpenDingDingFile(self):
        pass

    def getResult(self):
        pass

wqwe

# coding:utf-8
from Main import Main
from tkFileDialog import askopenfilename
import tkMessageBox as tkMB
from xl import FunctionInit
import sys

reload(sys)
sys.setdefaultencoding("utf-8")


class DingDing(Main):
    def __init__(self):
        Main.__init__(self)
        self.func = FunctionInit()

    def OpenDingDingFile(self):
        file_path = askopenfilename(filetypes=(("xls files", ("*.xls", "*.xlsx")),
                                               ("All files", "*.*")))
        print type(file_path)
        if not file_path:
            self.return_msg["text"] = '没有导入文件'
        elif file_path[len(file_path) - 3:] != 'xls' and file_path[len(file_path) - 4:] != 'xlsx':
            print file_path[len(file_path) - 3:]

            self.return_msg["text"] = '不是xls或者xlsx文件'
        else:
            # flag, msg = self.func.comple(file_path)
            print file_path
            self.LB1["text"] = str(file_path)

    def OpenKaoQinFile(self):
        file_path = askopenfilename(filetypes=(("xls files", ("*.xls", "*.xlsx")),
                                               ("All files", "*.*")))
        if not file_path:
            self.return_msg["text"] = '没有导入文件'
        elif file_path[len(file_path) - 3:] != 'xls' and file_path[len(file_path) - 4:] != 'xlsx':
            print file_path[len(file_path) - 3:]
            self.return_msg["text"] = '不是xls或者xlsx文件'
        else:
            # flag, msg = self.func.comple(file_path)
            self.LB2["text"] = str(file_path)

    def getResult(self):
        Lb2 = self.LB2["text"]
        Lb1 = self.LB1["text"]
        if Lb1 != '' and (Lb1[len(Lb1) - 3:] == 'xls' or Lb1[len(Lb1) - 4] == 'xlsx'):
            print "|", Lb2[len(Lb2) - 4], "|"
            if Lb2 != '' and Lb2[len(Lb2) - 4:] == 'xlsx':
                flag, msg, file_name = self.func.comple(Lb1, Lb2)
                self.return_msg["text"] = flag, msg, file_name
            else:
                tkMB.askokcancel("温馨提示", "考勤数据地址不是xls或者xlsx文件")

        else:
            tkMB.askokcancel("温馨提示", "考勤数据地址不是xls或者xlsx文件")


if __name__ == "__main__":
    dingding = DingDing()
    dingding.mainloop()
# coding:utf-8
import xlrd
import sys
from openpyxl import load_workbook
import time
reload(sys)
sys.setdefaultencoding("utf-8")


class FunctionInit():
    def comple(self, DataFromDing,DataFromKao):
        head = u'钉钉'
        FILE_NAME = str(time.strftime("%Y-%m-%d_%H%M%S", time.localtime())) + '.xlsx'
        FILE_NAME = head + FILE_NAME
        try:
            aworkbook = xlrd.open_workbook(DataFromDing)
            sheet1 = aworkbook.sheet_by_index(0)
            row3 = sheet1.row_values(3)
            len1 = len(row3)
            print len1
            s = ','.join(row3)
            s.decode('utf-8')
            emp = []
            emps = []
            employees = []
            row2 = sheet1.row_values(2)
            leave1 = int(row2.index('请假'.decode('utf-8').encode('utf-8')))
            print leave1
            len2 = 0

            for i in range(leave1, len1):
                if row3[i] == '':
                    len2 = i
                    break
            le = []
            if leave1 > 0:
                if len2 > 0:
                    for i in range(leave1, len2):
                        le.append(row3[i][:2])
                    for i in range(len2, len1):
                        le.append(row2[i][:2])
                else:
                    for i in range(leave1, len1):
                        le.append(row3[i][:2])
            print len(le)
            f = open('c', 'w')
            emp = []
            print len(sheet1.col_values(3))
            for i in range(4, (len(sheet1.col_values(3)) - 4)):
                dic = {}
                dic['name'] = sheet1.row_values(i)[3].split('(')[0]
                for ctype in le:
                    str_tmp = sheet1.row_values(i)[(le.index(ctype) + leave1)]
                    if str_tmp not in ['0', 0]:
                        print dic['name'],str_tmp[:len(str_tmp) - 2]
                        int_tmp = str_tmp[:len(str_tmp) - 2]
                        print '+++', str_tmp, '=='
                        dic[ctype] = int_tmp
                    else:
                        dic[ctype] = 0.0

                emp.append(dic)

            f.close()
            employees = []
            a = load_workbook(DataFromKao)
            c = a['附1人员清单']
            for row in c.iter_rows('c:c'):
                for cell in row:
                    employees.append(cell.value)
            list_leave = ['加班', '']
            for col in c.iter_rows('p1:y1'):
                for cell in col:
                    list_leave.append(cell.value[:2])
            with open('a', 'w') as f:
                f.write(','.join(list_leave))
            employees = employees[1:]
            for i in range(len(employees)):
                for j in range(14, 26):
                    c.cell(row=i + 2, column=j, value=0.0)
            for i in range(len(employees)):
                for j in range(len(emp)):
                    if employees[i] == emp[j]['name']:
                        print employees[i],
                        for key in emp[j]:
                            print list_leave
                            for tmp in range(len(list_leave)):
                                if list_leave[tmp] == key and key != '':
                                    c.cell(row=(i + 2), column=tmp + 14, value=emp[j][key])
                                    # print i + 2, tmp + 14, key, emp[j][key],
                                    break

                            print '||',
                        print
            result_flag = True
            return_msg = '解析成功'
            a.save(filename=FILE_NAME)
        except Exception, e:
            result_flag = False
            return_msg = '解析失败'
            print e
        finally:
            return result_flag, return_msg,FILE_NAME


if __name__ == "__main__":
    dingding = FunctionInit()
    dingding.comple('3.xls')

转载于:https://www.cnblogs.com/jian-pan/p/6560168.html

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_33816611/article/details/93375727

智能推荐

java笔记_笑容温暖城寨的博客-程序员宅基地

安卓课的Java扩展笔记包类命名规范总结输出换行与不换行mian方法中的args参数Math类快捷输出语句static关键字定义无参方法定义带返回值方法包package com.eoe.basic.day01;//包名 在java当中用.表示windos中的/,一般格式:com.公司名.项目名.业务模块名称例如:com.sina.crm.user类命名规范总结1、java中可以有多个类2、java中可以有多个类,但是最多只有一个类的类名和文件名相同3、如果一个类被public修饰,那该类

一、网络游戏架构的前世今生(2)_王元恺David的博客-程序员宅基地

网络游戏架构演进史,优化游戏网络,自定义网络协议

在Chrome 浏览器上滚动截屏_ianly梁炎的博客-程序员宅基地_横向滚动截图

浏览器滚动截屏,截取整个页面 在Chrome 浏览器上滚动截屏,不需要插件和任何 app,利用 chrome 浏览器原生功能即可实现。打开 Chrome 浏览器,进入需要截图的网站页面打开开发者工具:在页面任何地方点击鼠标右键,在弹出菜单中选择「检查」选项。或者使用快捷键组合:option + command + i。打开命令行(command palette):command + s...

微信小程序 获取用户网络状态和设备的信息_东边的小山的博客-程序员宅基地

var app = getApp()Page({ data: { motto: 'Hello World', userInfo: {}, netWorkType: '', phoneType: '', phoneSystemType: '', }, //事件处理函数 bindViewTap: function() { wx.nav...

CentOS7使用firewall-cmd打开关闭防火墙与端口_purple.taro的博客-程序员宅基地_firewall-cmd 关闭防火墙

先查看防火墙是否开启了1521端口:firewall-cmd --permanent --query-port=1521/tcp打印结果如下:no表示没有开放1521端口,那么添加下该端口:firewall-cmd --permanent --add-port=1521/tcp打印结果如下:success重新加载防火墙策略:firewall-cmd --reload执行成功后,查看1521端口是否被开启:firewall-cmd --permanent --query-port=152

MySQL、Oracle 通过SQL查看表注释、字段信息_白衣若尘的博客-程序员宅基地

MySQL: 查看表注释: 用 SHOW TABLE STATUS [FROM db_name] 示例: SHOW TABLE STATUS ; --数据库下所有表注释 SHOW TABLE STATUS FROM d

随便推点

大神博客地址_骏马传奇的博客-程序员宅基地

骏马金龙 http://www.cnblogs.com/f-ck-need-u/ 散尽浮华 http://www.cnblogs.com/kevingrace/ kris12 https://www.cnblogs.com/shengyang17/default.html?page=11 Edison Zhou https://www.cnblogs.com/...

圆排列问题_小张的java日记的博客-程序员宅基地_圆排列java

问题给定n个圆的半径序列,将它们放到矩形框中,各圆与矩形底边相切,求具有最小排列长度的圆排列。解析圆排列问题的解空间是一棵排列树。按照回溯法搜索排列树的算法框架,设开始时a=[r1,r2,……rn]是所给的n个元的半径,则相应的排列树由a[1:n]的所有排列构成。 首先计算圆在当前圆排列中的横坐标,由x^2 = sqrt((r1+r2)^2-(r1-r2)^2)推导出x = 2 * sqrt(r1 * r2)。然后计算当前圆排列的长度。变量lenmin记录当前最小圆排列长度...

获取颜色编码_Java_Hello_World.的博客-程序员宅基地

1,使用截屏功能2,正在截屏的时候按下shit,然后看到一个#c92027(red/红色)3,按下字母C4,到需要颜色代码的地方Ctrl+V

python 函数进阶_weixin_30951231的博客-程序员宅基地

三元运算a = 1b = 5c = a if a>b else bprint(c)构成变量 = 条件返回True的结果 if 条件 else 条件返回False的结果必须要有返回的结果必须要有if和else只能是简单的情况def func(a,b): return a if a>b else bc = func(3,5)...

rqt_graph提示b‘Format: “dot“ not recognized. Use one of:\n‘_qq_46145354的博客-程序员宅基地

在终端运行roscore,分别运行rosrun turtlesim turtle和rosrun turtlesim turtle_teleop_key,再输入rqt_graph,提示如下错误"dot" with args ['-Tdot', '/tmp/tmp145cvdav'] returned code: 1stdout, stderr:b''b'Format: "dot" not recognized. Use one of:\n'PluginHandlerDirect._resto.

form标签_ailihx的博客-程序员宅基地

这个标签会生成HTML form标签,同时为form内部所包含的标签提供一个绑定路径(binding path)。 它把命令对象(command object)存在PageContext中,这样form内部的标签 就可以使用这个对象了。标签库中的其他标签都声明在form标签的内部。 让我们假设有一个叫User的领域对象,它是一个JavaBean,有着诸如 firstName和lastName这