# -*- coding: cp936 -*-#python讀取Excelimport xlrddef main(): xls=xlrd.open_workbook("d://11.xls") try: mysheet=xls.sheet_by_name("Sheet1")#找到名為Sheet1的工作表。區(qū)分大小寫 except: PRint("沒有此工作表") return print("共有 %d 行, %d 列。"%(mysheet.nrows,mysheet.ncols))#將內(nèi)容逐個(gè)打印出來: for row in range(0,mysheet.nrows): for col in range(0,mysheet.ncols): if mysheet.cell(row,col).value != None: temp=mysheet.cell(row,col).value#將單元格里面的數(shù)據(jù)賦給temp print(type(temp))#依次打印出excel單元格里面的數(shù)據(jù)類型 print(temp)#依次打印出excel單元格里面的內(nèi)容if __name__=='__main__': main()
需要下載xlrd模塊:https://pypi.python.org/pypi/xlrd/0.8.0
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注