python使用xlrd模块可以读取xls和xlsx文件.
import xlrd import os file_addr = "E://test.xlsx" # xlsx文件存在 if os.path.exists(file_addr):
# 读取内容 xls_file = xlrd.open_workbook(file_addr)
# 取第一个sheet页 xls_sheet = xls_file.sheets()[0]
# 第一个sheet页的行数和列数 nrows = int(xls_sheet.nrows) ncols = int(xls_sheet.ncols)
# 读取每一行,一般不读第一行,因为是表头
for now in range(1,nows):
拿到每行的数据,结构是列表,通过索引取每一个字段内容
rows_value = xls_sheet.row_values(row)
结束!