0

Using xlwings in Python, I've been able to add cell borders and set their weight. But unfortunately every time I try to change the border color, the code gets stuck

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

Any idea what might be causing it?

Mike
  • 102
  • 6

1 Answers1

1

You can use :

#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

Output :

enter image description here

Timeless
  • 22,580
  • 4
  • 12
  • 30