Python中使用Xlwings的Excel边框颜色

oxalkeyp  于 2023-06-07  发布在  Python
关注(0)|答案(1)|浏览(156)

在Python中使用xlwings,我已经能够添加单元格边框并设置它们的权重。但不幸的是,每次我尝试更改边框颜色时,代码就会卡住

import xlwings as xw
sheet = xw.sheets[0]
cells = sheet.range((2,2),(2,6))
cells.api.Borders(11).Weight = 3
cells.api.Borders(11).Color = '#ffffff' # This line gets the code stuck

知道是什么引起的吗

7xllpg7q

7xllpg7q1#

您可以用途:

#https://stackoverflow.com/a/21338319/16120011
def rgbToInt(rgb):
    colorInt = rgb[0] + (rgb[1] * 256) + (rgb[2] * 256 * 256)
    return colorInt

wb = xw.Book()

sheet = wb.sheets[0]

cells = sheet.range((2, 2), (2, 6))
cells.api.Borders(11).Weight = 3
cells.api.Borders(11).Color = rgbToInt((0, 0, 0)) #black color

输出:

相关问题