Python之Excel操作,pythonexcel

來源:互聯網
上載者:User

Python之Excel操作,pythonexcel

Python的Excel操作需要另外下載安裝對應Python版本的xlrd和xlwt包,用於對Excel的讀取和寫入。

安裝方法:直接解壓後,在字元命令介面cd到setup.py的目錄,執行命令“Python setup.py install”即可。

xlrd(下面有些是方法,有些是屬性,屬性後面不加括弧)

1. excel = xlrd.open_workbook(excel_path):開啟指定路徑的Excel檔案,得到對應Excel的Excel對象(整個Excel檔案的對象)。

2. excel_lst = excel.sheets:以列表的形式返回Excel對象中的sheet(Excel中單個sheet對象)。

3. excel_sheet = excel.sheet_by_name(sheet_name):根據sheet的名字擷取sheet對象。

4. excel_sheet = excel.sheet_by_index(sheet_index):根據sheet的索引(按照Excel中的sheet順序以0開始)擷取sheet對象。

5. excel_sheet.nrows:sheet中的有效行數。

6. excel_sheet.ncols:sheet中的有效列數。

7. excel_sheet.name:sheet的名稱。

8. excel_sheet.cell(row, col).value:擷取指定儲存格的值。

9. excel_sheet.row_values(row):以列表的形式返回指定行的資料。

10. excel_sheet.col_values(col):以列表的形式返回指定列的資料。

11. excel_sheet.put_cell(row, col, type, value, xf):對儲存格進行簡單的寫入(type為數字:0 empty, 1 string, 2 number, 3 date, 4 boolean, 5 error;xf=0:拓展的格式化)(本方法沒有實驗過,讀者可用時自行實驗)。

 

xlwt

整理更新中...

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.