首页 技术 正文
技术 2022年11月11日
0 收藏 683 点赞 3,265 浏览 3266 个字

1、源码:先写一个界面出来,放需要放入的点击事件的函数

# -*- coding:utf-8 -*-
import Tkinter
from Tkinter import *import ExcleCount#定义点击事件
def butonck():
input_path = entry_input.get().strip() ExcleCount.excleCount_passenger(input_path)top = Tkinter.Tk()
# 标题
top.title("excel计数工具")
# 窗口大小 长高用小写x隔开
top.geometry("400x200")
# 窗口基于屏幕的坐标 +x轴+y轴
top.geometry("+500+200")
# input_dir_text = Entry(top)# 创建lab标签 填写文件的输入路径
label_input = Label(top, text="excle文件路径:", fg="red", font=("宋体", 12))
# 显示lab标签 网格布局 sticky=W #左对齐 E为右对齐 默认为中间对齐
label_input.grid(row=0, column=0, padx=6, pady=10)# # 创建输入框,填写文件路径
entry_input = Entry(top, font=("宋体", 12))# 显示输入框
entry_input.grid(row=0, column=1)# 创建lab标签 填写文件的输入路径
# label_out = Label(top, text="口岸文件路径:", fg="red", font=("宋体", 12))
# # 显示lab标签 网格布局 sticky=W #左对齐 E为右对齐 默认为中间对齐
# label_out.grid(row=1, column=0)# # 创建输入框,填写文件路径
# entry_out = Entry(top, font=("宋体", 12))
#
# # 显示输入框
# entry_out.grid(row=1, column=1)# 创建按钮
button = Button(top, text="确定", font=("宋体", 15), command=butonck)
# 显示按钮
button.grid(row=2, column=1, padx=6, pady=10)
# 进入消息循环
top.mainloop()

2、处理excle的某个功能函数

#!/usr/bin/env python
# -*- coding: utf-8 -*-import xlsxwriter
import os
import win32com.client as win32def excleCount_passenger(file_path):
#定义输出的文件路径在原始文件的路径的同级目录新建一个outfile
file_list = []
out_file_path = os.path.join(os.path.abspath(os.path.dirname(file_path)+os.path.sep+"."), 'out_file')
if not os.path.exists(out_file_path):
os.makedirs(out_file_path)
for root, dirs, files in os.walk(file_path):
for name in files:
excle_file_name = os.path.join(file_path, os.path.join(root, name))
if name.endswith('.xls') or name.endswith('.xlsx'):
#print(excle_file_name)
file_list.append(excle_file_name) #打开excle excel = win32.Dispatch("Excel.Application")
excel.Visible = False
excel.DisplayAlerts = False xlBook = excel.Workbooks.Open(file_list[0])
sheetname = xlBook.Sheets(1).Name
# print ex sht = xlBook.Worksheets(sheetname) # sheet的行数
nrows = sht.UsedRange.Rows.Count # sheet的列数
ncols = sht.UsedRange.Columns.Count for j in range(1, ncols + 1):
if sht.Cells(1, j).Value == u'证件号码':
numOf = j set_data1 = set()
for i in range(2, nrows + 1): travel = sht.Cells(i, numOf).Value.decode('utf-8')
set_data1.add(travel)
print("set1",set_data1)
# xlBook 关闭读取excle进程
xlBook.Close(SaveChanges=1) # 关闭xlBook句柄 del excel # 这个地方很重要,杀死excel进程是这个地方起作用
# 打开excle excel = win32.Dispatch("Excel.Application")
excel.Visible = False
excel.DisplayAlerts = False xlBook = excel.Workbooks.Open(file_list[1])
sheetname = xlBook.Sheets(1).Name
# print ex sht = xlBook.Worksheets(sheetname) # sheet的行数
nrows = sht.UsedRange.Rows.Count # sheet的列数
ncols = sht.UsedRange.Columns.Count
for j in range(1, ncols + 1):
if sht.Cells(1, j).Value == u'证件号码':
numOf = j set_data2 = set()
for i in range(2, nrows + 1):
# print(sht.Cells(i, 10).Value,type(sht.Cells(i, 10).Value))
# if isinstance(sht.Cells(i, 10).Value, unicode):
travel = sht.Cells(i, numOf).Value.decode('utf-8')
set_data2.add(travel)
#print("set2",set_data2)
# xlBook 关闭读取excle进程
xlBook.Close(SaveChanges=1) # 关闭xlBook句柄 del excel # 这个地方很重要,杀死excel进程是这个地方起作用 end_list = []
for i in set_data1:
for j in set_data2:
if i == j:
end_list.append(i)
#print(end_list) workbook = xlsxwriter.Workbook(os.path.join(out_file_path, 'out.xlsx'))
worksheet = workbook.add_worksheet('sheet1')
headings = [u'去重交集数据'] # 设置表头 data = [end_list]
worksheet.write_row('A1', headings)
worksheet.write_column('A2', data[0])
workbook.close()

3、打包代码

pyhton2.7
前提第三方库已经安装pip install pyinstaller打包的整个路径不能放中文
pyinstaller -i Excel.ico -w -D excelTool.py ExcleCount.py -p C:\Python27\Lib\site-packages

上面的Excel.ico是图标文件图片 —D 参数后面第一个跟界面主函数 -p 加上环境依赖的第三方包
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,031
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,860