2015-09-26 179 views
2

在openpyxl,你可以设置这样一个超级链接: 超链接样式在Openpyxl

cell.hyperlink = r'..\somedir\somefile.txt' 

然而,这并不适用超链接样式设置在Excel中的超链接时,你会得到。您可以使用蓝色文本和下划线应用样式,但是当您打开文档时,访问的超链接不会更改颜色。

有没有什么办法用openpyxl来指定一个超链接样式,就像在Excel中设置超链接一样?

回答

0

尝试添加超链接的风格类似这样的

ft = Font() 
ft.underline = 'single' # add single underline 
ft.color = Color(rgb='000000FF') # add blue color 
cell.font = ft 
0

我用了一个Font和它的工作。

from openpyxl.styles import Font 
hyperlink = Font(underline='single', color='0563C1') 
# ... 
cell.font = hyperlink 

有应该是一个builtin sytle命名Hyperlink,但我没有设法使其工作...