本文对xlsx文件的读写使用以下的库,已安装的可以忽略:
""" 需安装的库文件: pip install xlrd==1.2.0 pip install pywin32 换源网址: - 豆瓣:http://pypi.douban.com/simple/ - 中科大:https://pypi.mirrors.ustc.edu.cn/simple/ - 清华:https://pypi.tuna.tsinghua.edu.cn/simple 换源安装,例如:pip install pywin32 -i https://pypi.tuna.tsinghua.edu.cn/simple """xlsx文件的读操作:
1.读一行数据
# 读一行
# 参数解读:get_row(excel的路径,选择的子表格名字,所读行的位置)
def get_row(file_path, subtable, row_location):
# 打开excel表格
filename = xlrd.open_workbook(file_path)
# 打印excel所有子表格的名字
form_name = filename.sheet_names()
# 获取选择子表格的位置
subtable_location = form_name.index(subtable)
# 选择子表格为操作对象
sheet = filename.sheet_by_index(subtable_location)
# 获取选取对象的行列值
rowNum = sheet.nrows
colNum = sheet.ncols
# 获取某一行的数据
row_allvalue = sheet.row_v


