目前使用 Openpyxl。我知道 append 將在 excel 中按行列印輸出。我試圖弄清楚是否有一個函式可以在列中列印輸出。例如:
headings = ['Name','Fruits']
ws.append(headings)
Name = ['John','Ben','Lily','Sarah']
Fruits = ['Orange','Apple','Grape','Peach']
excel中的輸出:
A B
1 Name Fruits
2 John Orange
3 Ben Apple
4 Lily Grape
5 Sarah Peach
uj5u.com熱心網友回復:
您正在尋找的資訊顯示在這里。該示例顯示了如何迭代列和行,這最終只是簡單的網格/矩陣邏輯。
from itertools import cycle
c = cycle([1, 2])
for idx in range(len(Name)):
ws.cell(column=next(c), row=idx, value=Name[idx])
ws.cell(column=next(c), row=idx, value=Fruits[idx])
# Column 1, Row 0 John
# Column 2, Row 0 Orange
# Column 1, Row 1 Ben
# Column 2, Row 1 Apple
# etc...
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/406117.html
標籤:
