前言
为使python读取excel文件内容,需使用xlrd模块来处理
模块使用步骤
导入模块
pip install xlrd
打开工作簿
readExcelWorkbook = xlrd.open_workbook(“excel文件路径”)
获取表
readExcelTable = readExcelWorkbook.sheet_by_index(表序号)
readExcelTable = readExcelWorkbook.sheet_by_index(“表名”)
获取表单内容
getValue = readExcelTable.cell_value(行值, 列值)
getValue = readExcelTable.cell(行值, 列值).value
getValue = readExcelTable.row(行值)[列值].value
相关属性详见下图所示
代码示例
import xlrd
readExcelWorkbook = xlrd.open_workbook("different_mysql_version_contrast.xls")
readExcelTable = readExcelWorkbook.sheet_by_index(0)
# getValue = readExcelTable.cell_value(1, 1)
# getValue = readExcelTable.cell(1, 1).value
getValue = readExcelTable.row(1)[1].value
print(getValue)
“transaction_write_set_extraction”
结语
参考python官方指导手册: python-excel