劉任昌python處理excel檔案

import openpyxl   #劉任昌輸入import openpyxl處理EXCEL的函式庫
book = openpyxl.load_workbook(r'wb.xlsx') #開啟EXCEL工作簿wb.xlsx
print("1. 列出所有工作表名稱")
sheetNames=book.sheetnames                #所有工作表的集合
for name in sheetNames:
   print(name)

print("2. 針對特定工作表, 列出前面數列")
sheet = book["python"]   #將工作表python稱為sheet
for row in sheet.iter_rows(min_row=1, max_row=3, min_col=1, max_col=5, values_only=True):
    print(row)
    
print("3. 列出工作表所有內容")
x = sheet["A1"].value     #將A1的年月日存在x
sheet["A1"] = "劉任昌" + x
sheet["F1"] = "波段H"
sheet["G1"] = "波段L"
sheet["H1"] = "部位"
sheet["I1"] = "損益"
sheet["F2"], sheet["G2"], sheet["H2"], sheet["I2"]=sheet["C2"].value, sheet["D2"].value, 0, 0
for row in sheet.iter_rows(min_row=1, max_row=3, min_col=1, max_col=9, values_only=True):
    print(row)
book.save("劉任昌.xlsx")

留言

  1. https://d10917217.blogspot.com/2023/05/pythonexcel.html

    回覆刪除
  2. https://10917324.blogspot.com/2023/05/python-import-openpyxl-excel.html

    回覆刪除
  3. https://kenyeh123.blogspot.com/2023/05/pythonexcel.html

    回覆刪除
  4. https://chienchiwei.blogspot.com/2023/05/526.html

    回覆刪除
  5. https://lin60616.blogspot.com/2023/05/blog-post.html

    回覆刪除
  6. https://www.blogger.com/blog/post/edit/6636358029867254966/6202417127730218171

    回覆刪除
  7. https://remonti0119.blogspot.com/2023/05/python-excel.html

    回覆刪除
  8. https://d10917203.blogspot.com/2023/05/pythonexcel.html

    回覆刪除
  9. https://dddd6420.blogspot.com/2023/05/import-openpyxl-import-openpyxlexcel.html

    回覆刪除
  10. https://weizhezhantvsdexcr.blogspot.com/2023/05/pythonexcel.html

    回覆刪除
  11. https://d10917350.blogspot.com/2023/05/pythonexcel.html

    回覆刪除
  12. https://d10917206.blogspot.com/2023/05/pythonexcel.html

    回覆刪除
  13. https://d10950132.blogspot.com/2023/06/pythonexcel.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

馬可維茲風險平均數平面

2025年3月7日福斯汽車與遊戲驛站軋工事件

劉任昌利用Python讀取SPY日成交資料(繳交作業情形)