1. 程式人生 > >Python 讀取xlsx表格

Python 讀取xlsx表格

#!user/bin/python3
#coding:utf-8


import xlrd


file = '這裡填要讀取的檔案的絕對路徑'
wb = xlrd.open_workbook(filename=file)
print(u'表格中Sheet為:',wb.sheet_names())

# 通過索引獲取表格
sheet1 = wb.sheet_by_index(0)

# 獲取行內容
rows1 = sheet1.row_values(1,1)
rows2 = sheet1.row_values(2)
print(rows1)
print(rows2)



# 獲取列內容
cols1 = sheet1.col_values(1)
cols2 = sheet1.col_values(2)
print(cols1)
print(cols2)


'''''''''

#獲取表格裡的內容,三種方式
print(sheet1.cell(1,0).value)
print(sheet1.cell_value(1,0))
print(sheet1.row(1)[0].value)
'''