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)
結束!