python(2)-操作excel

1.

1)用管理员身份打开dos命令行----pip  install openpyxl

2)用管理员身份运行 pycharm

 

#存到excel里面,python去操作excel文件
#只支持这种后缀,xlsx  ,openpyxl只支持这种格式
#pip  install openpyxl

from openpyxl import load_workbook

#1:打开文件,加载用例薄
wb=load_workbook("D:\\test.xlsx")    #和file=open()差不多
#2:定位表单
sheet = wb['test_sheet1']  #test_sheet1是sheet表的名字
#3:定位单元格
res1 = sheet.cell(row=1, column=1).value
print(res1)
'''
print(sheet.max_column)
print(sheet.max_row)'''


res2 = sheet.cell(row=2, column=2).value
print(res2)
'''print(sheet.max_column)
print(sheet.max_row)'''


res3 = sheet.cell(row=3, column=3).value
print(res3)
'''print(sheet.max_column)
print(sheet.max_row)'''
参考文档:https://www.cnblogs.com/wuzm/p/11977694.html 感谢博主





posted @ 2020-02-19 15:36  阳光美美哒  阅读(340)  评论(0编辑  收藏  举报