英文:
Excel Border Color with Xlwings in Python
问题
I've been able to add cell borders and set their weight using xlwings in Python. However, 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
有什么可能导致这个问题的想法吗?
英文:
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?
答案1
得分: 1
你可以使用:
#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)) #黑色
输出:
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/GTQ2v.png
英文:
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 :
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论