首先,openpyxl的安装方法是在windows的命令行中用pip工具进行安装:
pip install openpyxl
然后再ipython中,要想访问某个excel表,需要先将python的当前工作路径转换到excel表格所在的路径
import os
import os.getcwd()
import os.chdir('E:\\pigshow\\学术\\02-理论书籍\\20-Python\\Python编程快速上手-让繁琐工作自动化\\automate_online-materials')
然后来获取excel表格的sheet1表格的行数与列数:
>>> import openpyxl
>>> wb = openpyxl.load_workbook('example.xlsx')
>>> sheet = wb.get_sheet_by_name('Sheet1')
>>> sheet.max_row
7
>>> sheet.max_column
3