sunjiali
# 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')