openpyxl處理Excel——(行數、列數)


參考資料:

https://www.testwo.com/blog/7269

 

#導入openpyxl
from openpyxl import load_workbook

#創建文件路徑
path=r"E:\"
filename=“test.xlsx”
filepath=path+filename

#打開excel
xl=load_workbook(filepath)
#獲取所有sheet頁名字
xl_sheet_names=xl.get_sheet_names()
#打印所有sheet頁名稱
print(xl_sheet_names)

#定位到相應sheet頁,[0]為sheet頁索引
xl_sheet=xl.get_sheet_by_name(xl_sheet_names[0])

#獲取行列數
row=xl_sheet.max_row
column=xl_sheet.max_column

#獲取單元格值
xl_cell=xl_sheet.cell(row=i,column=j).value

#單元格賦值
xl_cell=xl_sheet.cell(row=i,column=j,value=“金額”)

#保存excel
xl.save(filepath)

 


免責聲明!

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



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