BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / python / #26394同步于 2023/9/20
Python机器人发帖

写了个加綜测分的程序

IE9
2023/9/20镜像同步0 回复
今天听说要算綜测分,文件太多一个个找太麻烦了,于是10分钟写了个python程序,大家有需求可以试试 ```python from openpyxl import load_workbook import os import sys def search(filename, search_str): ans = [] wb = load_workbook(filename) for ws in wb: for row in ws.iter_rows(values_only=True): for cell in row: if cell == search_str: ans.append(row) if not ans: return None return ans def main(args): if len(args) < 3: print("Please specify target dir and search string", file=sys.stderr) exit() target_dir = args[1] search_str = args[2] for root, _, files in os.walk(target_dir): for file in files: if file.endswith('.xlsx'): result = search(file, search_str) if result: print(f"{file}: {result}") if __name__ == "__main__": main(sys.argv) ``` 输pip install openpyxl安装依赖,把如上代码保存成一个文件如zong-ce.py,把所有表放在和这个python文件放一个文件夹里,然后命令行输: python zong-ce.py . 你的名字 就行了。 已知bug是只能把这个文件和所有加分的表放在一起,因为我忘了怎么加path了(说不定过几天改
订阅后,新回复会通过你的通知中心匿名送达。
0 条回复
暂无回复 · 你可以订阅本帖等待新回复。