Python 版本
目前 Python 3 版本为主流版本,这里测试的版本是:Python 3.10.5。
常用库说明
Python 操作 Excel 的常用库有:xlrd、xlwt、xlutils、openpyxl、pandas。这里主要说明下 Excel 文档 .xls 格式和 .xlsx 格式的文档打开和读取。
Python 操作 .xls 格式的 Excel
参考网址:xlrd — xlrd 2.0.1 documentationhttps://xlrd.readthedocs.io/en/latest/
import xlrd
# 定义文件路径并打开文件
filePath = r'C:\Users\mengll\Desktop\测试的EXCEL文档.xls'
file = xlrd.open_workbook(filePath)
# Excel Sheet 页数量:file.nsheets
print("这个表格一共有的sheet数量是: {0}".form