openpyxl 中的邊框

鮑比

我正在嘗試在 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)
代碼猴子

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')    

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章