帮女朋友统计用的,由于前一篇文章提到的Excel严重bug,改用Python来处理了
需要安装xlrd模块
代码如下
# -*- coding: UTF-8 -*-
import xlrd
dirs = 'C:\\Users\\Administrator\\Desktop\\某单位\\2012工资数据\\'
names = ['在岗2017.1.xls','在岗2017.2.xls','在岗2017.3.xls','在岗2017.4.xls','在岗2017.5.xls','在岗2017.6.xls','在岗2017.7.xls']
#dirs = 'C:\\Users\\Administrator\\Desktop\\'
#names = ['在岗2017.2.xls','zaigang02out.xls']
for i in range(1,len(names)):
print(i)
table1 = xlrd.open_workbook(dirs+names[i-1]).sheets()[0]
table2 = xlrd.open_workbook(dirs + names[i]).sheets()[0]
dict1={}
dict2={}
nrows1 = table1.nrows
nrows2 = table2.nrows
for j in range(1, nrows1):
dict1[table1.row_values(j)[0]] = table1.row_values(j)[2]
for j in range(1, nrows2):
dict2[table2.row_values(j)[0]] = table2.row_values(j)[2]
print(names[i] + '对比' + names[i - 1] + '部门变动\n')
print('减少了'+str(nrows1-nrows2)+'人\n')
count = 0
for k in dict2:
if(dict2[k]!=dict1[k]):
print(k+':'+dict2[k]+'\n')
count = count+1
print('调动了' + str(count) + '人\n')