python讀取excel以及python全套安裝


python安裝:python2於python3的語法不一樣,我都不會,建議安裝python3,在安裝時記得添加環境變量,python的卸載也是用安裝包卸載的,其他過程略

pycharm安裝:開源版,裝上就行

pip安裝(管理擴展包之類的東西,有了這個才可以讀excel):這篇親測有效,其他的看起來都很麻煩 傳送門

使用包的時候需要在pycharm中添加進去,參照這篇

excel的使用方法,這里是關於python3的,寫的挺清楚的(傳送門

下面是我自己寫的關於python讀寫excel的代碼:

 算了太懶了

import xlwt
import xlrd
import openpyxl

name = "test.xlsx"
book = xlrd.open_workbook(name)
sheet = book.sheet_by_index(0)
n = sheet.nrows
m = sheet.ncols

newbook = openpyxl.Workbook()
newsheet = newbook.get_active_sheet()

cnt = 1;
for i in range(1, n + 1) :
    for j in range(1, m + 1) :
        newsheet.cell(cnt + i - 1, j, sheet.cell(i - 1, j - 1).value)
cnt += n;

name = "test1.xlsx"
book = xlrd.open_workbook(name)
sheet = book.sheet_by_index(0)
n = sheet.nrows
m = sheet.ncols
for i in range(1, n + 1) :
    for j in range(1, m + 1) :
        newsheet.cell(cnt + i - 1, j, sheet.cell(i - 1, j - 1).value)
cnt += n
newbook.save("test2.xlsx")
print("success")

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM