# -*- coding: utf-8 -*-
import xlrd
def read_excel():
# 文件位置
? ? excel_file = xlrd.open_workbook(r'F:\小區(qū)參數(shù)規(guī)劃\NeighborOutput_result.xlsx')
# 獲取目標(biāo)EXCEL文件sheet名
? ? sheets = excel_file.sheets()
for sheetin sheets:
# 打印sheet的名稱剔难,行數(shù),列數(shù)
? ? ? ? print(sheet.name, sheet.nrows, sheet.ncols)
# 獲取整行或者整列的值
? ? ? ? rows = sheet.row_values(2)# 第三行內(nèi)容
? ? ? ? cols = sheet.col_values(1)# 第二列內(nèi)容
? ? ? ? print(cols, rows)
# 獲取單元格內(nèi)容
? ? ? ? print(sheet.cell(1, 0).value)
print(sheet.cell_value(1, 0))
print(sheet.row(1)[0].value)
# 打印單元格內(nèi)容格式
? ? ? ? print(sheet.cell(1, 0).ctype)
if __name__ =='__main__':
read_excel()