python在CMD界面讀取excel所有數(shù)據(jù)的示例
代碼
import xlrdimport os from prettytable import PrettyTableimport pandas#創(chuàng)建一個(gè)Excel表類class Excel(object): def __init__(self, path): self.path = path //路徑要加上文件名 #讀取Excel內(nèi)全部數(shù)據(jù) 參數(shù)sname是sheet頁(yè)名字 def read_all_data(self, sname): workbook = xlrd.open_workbook(self.path) content = workbook.sheet_by_name(sname) # ord_list=[] ord_list = PrettyTable() for rownum in range(content.nrows): ord_list.add_row(content.row_values(rownum)) # ord_list.append(content.row_values(rownum)) #返回的類型是一個(gè)list return ord_listif __name__ == '__main__': path = input('-->>>Enter your path: ')xl = pandas.ExcelFile(path)sheetsname = xl.sheet_namesprint('all your excel sheetsname: ' + str(sheetsname))# print(sheetsname)sheetname = input('-->>>Enter your excel sheet name: ')path1 = Excel(path)alldata = path1.read_all_data(sname=sheetname)# alldata = PrettyTable(alldata)print(alldata)
演示
加了prettytable美化顯示
以上就是python在CMD界面讀取excel所有數(shù)據(jù)的示例的詳細(xì)內(nèi)容,更多關(guān)于python讀取excel數(shù)據(jù)的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. chat.asp聊天程序的編寫(xiě)方法2. JSP之表單提交get和post的區(qū)別詳解及實(shí)例3. 利用FastReport傳遞圖片參數(shù)在報(bào)表上展示簽名信息的實(shí)現(xiàn)方法4. PHP循環(huán)與分支知識(shí)點(diǎn)梳理5. Ajax請(qǐng)求超時(shí)與網(wǎng)絡(luò)異常處理圖文詳解6. JSP+Servlet實(shí)現(xiàn)文件上傳到服務(wù)器功能7. jsp實(shí)現(xiàn)textarea中的文字保存換行空格存到數(shù)據(jù)庫(kù)的方法8. ASP中格式化時(shí)間短日期補(bǔ)0變兩位長(zhǎng)日期的方法9. JavaWeb Servlet中url-pattern的使用10. jsp EL表達(dá)式詳解
