openpyxl讀寫(xiě) Excel 文件的 Python 庫(kù)
openpyxl是一個(gè)Python庫(kù),用于讀取/寫(xiě)入Excel 2010 xlsx / xlsm / xltx / xltm文件。
它的誕生是因?yàn)槿鄙倏蓮腜ython本地讀取/寫(xiě)入Office Open XML格式的庫(kù)。
示例代碼如下:
from openpyxl import Workbook
wb = Workbook()
# grab the active worksheet
ws = wb.active
# Data can be assigned directly to cells
ws['A1'] = 42
# Rows can also be appended
ws.append([1, 2, 3])
# Python types will automatically be converted
import datetime
ws['A2'] = datetime.datetime.now()
# Save the file
wb.save("sample.xlsx")評(píng)論
圖片
表情
