python 模組openpyxl讀excel檔案

來源:互聯網
上載者:User

標籤:load   模組   image   int   for   nbsp   技術   python   擷取   

使用openpyxl模組來讀取excel。

先看一下操作前的excel是什麼樣子吧。對了,現在只支援xlsx格式的excel讀取

 

 我現在想在第三行插入3,3,3怎麼辦呢?

#!/usr/bin/env python# _*_ coding:utf-8 _*_# 匯入excel讀模數塊from openpyxl import load_workbookfrom openpyxl.cell import get_column_letter# 將excel檔案載入到記憶體對象中wb = load_workbook(filename=u‘C:\kong_t1.xlsx‘)# 擷取所有sheet頁# SheetNames = wb.get_sheet_names()SheetNames = wb.sheetnames# 擷取第一個sheet頁內的資料ws = wb.get_sheet_by_name(SheetNames[0])
#擷取sheet中最大行數與最大列數rows = ws.max_rowcols = ws.max_columnfor i in range(1,rows+1): for l in range(1,cols+1): col = get_column_letter(l) print ws.cell(‘%s%s‘%(col,i)).value#在檔案最後追加一行資料ws.append([3,3,3])wb.save(‘kong.xlsx‘)

  最終

 

python 模組openpyxl讀excel檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.