xlrd和xlwt是python操作excel的两个库,xlrd用于读取,xlwt用于写入。xlwt无法直接操作xlrd读取的excel数据,需要使用xlutils3将xlrd读取的excel拷贝成xlwt可操作对象。
安装
pip install xlrd
pip install xlwt
pip install xlutils
导入
import xlrd
import xlwt
import xlutils
目录
-
读取excel
读取excel
# ----读取excel----
data= xlrd.open_workbook(excel_file)
读取sheet
# ----读取sheet----
# 通过索引顺序获取sheet
table = data.sheets()[0]
# 通过索引顺序获取sheet
table = data.sheet_by_index(0))
# 通过名称获取sheet
table = data.sheet_by_name("sheet")
# 返回book中所有sheet的名字
names = data.sheet_names()
# 传入索引或sheet名检查某个sheet是否导入完毕
table.sheet_loaded(&#