对比excel
from os.path import exists
from xlwings import App
import yaml
def check_list_tool():
if not exists('主管.xlsx'):
print("缺少主管文件,无法比较")
else:
# 比较横梁
if exists('横梁.xlsx'):
do_compare('主管.xlsx','横梁.xlsx',"横梁data","横梁data","B1:B50")
print("横梁比较已完成")
if exists('立柱.xlsx'):
do_compare('主管.xlsx','立柱.xlsx',"立柱data","立柱data","B1:B50")
print("立柱比较已完成")
if exists('滑块.xlsx'):
do_compare('主管.xlsx','滑块.xlsx',"滑块data","滑块data","B1:B50")
print("滑块比较已完成")
if exists('底座.xlsx'):
do_compare('主管.xlsx','底座.xlsx',"底座data","底座data","B1:B50")
print("底座比较已完成")
if exists('平衡器.xlsx'):
do_compare('主管.xlsx','平衡器.xlsx',"平衡器data","平衡器data","B1:B50")
print("平衡器比较已完成")
def do_compare(super_book_name,design_book_name,super_sheet_name,design_sheet_name,range_to_conpare):
app = App(visible=True, add_book=False)
super_book = app.books.open(super_book_name)
design_book = app.books.open(design_book_name)
for row in super_book.sheets[super_sheet_name].range(range_to_conpare):
for super_cell in row:
design_cell = design_book.sheets[design_sheet_name].range(super_cell.address)
if super_cell.value != design_cell.value:
super_cell.color = design_cell.color = (255, 180, 180)
else:
super_cell.color = design_cell.color = (200, 255, 200)
super_book.save()
super_book.close()
design_book.save()
design_book.close()
app.quit()
if __name__ == '__main__':
print("1.请先确认excel已彻底关闭")
print("2.请保证文件名称符合程序规定: 主管.xlsx 横梁.xlsx 立柱.xlsx 滑块.xlsx 底座.xlsx ")
print("3.请确保文件夹中包含 主管.xlsx, 以及其他待比较文件,以及内部sheet的名字没有被改动")
print("4.比较过且一致的是绿色,不一致的是红色")
print("继续请按回车")
input()
check_list_tool()
print("程序已结束 ^_^,按任意键退出")
input()
打包成exe。直接安装pyinstaller。
运行这个,在pycharm的terminal中运行一次,会超过迭代次数。此时加入下面的代码。可以搜到教程。
import sys ; sys.setrecursionlimit(sys.getrecursionlimit() * 5)
标签:脚本,xlsx,data,excel,book,design,print,super,对比 From: https://www.cnblogs.com/ziwenzhao95/p/18141838