舉個例子:由於當今原物料價格變化快速,所以我們可以用excel的time 模組的 striftime()函數,來記錄每天的原物料行情。註
strtime("%Y/%m/%d")函數可以回傳年/月/日格式的日期
#ch2_5.py
import openpyxl
from openpyxl.styles import Font
import os
import time
# 切換到指定路徑
os.chdir(r"C:\Catherine_Files")
wb = openpyxl.Workbook() #建立空白wb
ws = wb.active
ws['A1'] = time.strftime("%Y/%m/%d")
ws['A2'] = '期貨行情'
ws['A3'] = '小麥'
ws['A4'] = '玉米'
ws['B3'] = 1097
ws['B4'] = 742
wb.save('out2_5.xlsx') #儲存wb