我正在嘗試在 excel 中為最大行應用邊框。下面是我的代碼,我收到錯誤 'Int' object is not iterable 有人幫我根據最大行在 excel 中應用邊框嗎?
sheet = 是作業表
from openpyxl.styles import Border, Side,
row = sheet.max_row
thin = Side(border_style="thin", color="000000")
for cell in row:
cell.border = Border(top=thin, left=thin, right=thin, bottom=thin)
uj5u.com熱心網友回復:
sheet.max_row 是一個數字而不是一個可迭代的物件。
你幾乎讓它作業了。如果想使用 openpyxl 在作業表的最后一行設定邊框,請嘗試以下操作:
row = sheet.max_row
thin = Side(border_style="thin", color="000000")
for col in range(1, sheet.max_column 1):
cell = ws.cell(row=row, column=col)
cell.border = Border(top=thin, left=thin, right=thin, bottom=thin)
wb.save('newfile.xlsx')
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/349390.html
