环境:python3
判断当前路径是否存在指定excel表格
不存在则创建
打开表格
写入数据
关闭表格
from openpyxl import Workbook from openpyxl import load_workbook import os name = "信息录入.xlsx" if os.path.exists(name): pass else: # 如果没有表格则创建一个表格 wb = Workbook() ws = wb.active wb.save(name) wb = load_workbook('信息录入.xlsx') ws = wb.active liebiao = ["1","2"] ws.append(liebiao) wb.save("信息录入.xlsx")