import json,time
from openpyxl.workbook import Workbook
from openpyxl import load_workbook
def write_to_excel(local,value,dir):
workbook = load_workbook(dir)
worksheet1 = workbook.active
worksheet1[local] = value
print('将'+value+'写入excel的单元格'+local)
workbook.save(dir)
def read_from_excel(local,dir):
workbook = load_workbook(dir)
worksheet1 = workbook.active
content = worksheet1[local].value
print(local+'单元格的值是:'+content)
return(content)
if __name__ == '__main__':
print("输入文件的地址和文件名:")
dir = input()
write_to_excel('a1','测试111',dir)
read_from_excel('a1',dir)
效果:
在这里插入图片描述