我想在excel的单元格中的文本下方添加一个url作为链接,以便用户可以访问该站点。我正在努力,但它不起作用。请帮忙
base = xlwt.Workbook()
for k,v in MainDict.items():
base.add_sheet(k)
xlwt.add_palette_colour("custom_colour", 0x21)
base.set_colour_RGB(0x21, 251, 228, 228)
style = xlwt.easyxf('pattern: pattern solid, fore_colour custom_colour;font : bold on')
style1 = xlwt.easyxf('font : underline single')
index = MainDict.keys().index(k)
ws = base.get_sheet(index)
col=0
for sk in MainDict[k].keys():
ws.write(0,col,sk.upper(),style)
col+=1
row =1
for mk in MainDict[k][sk].keys():
for lk,lv in MainDict[k][sk][mk].items():
for items in lv:
ws.write(row,col-1,(items + str(Formula('HYPERLINK("%s")'%mk))))
row+=1
base.save('project2.xls')
答案 0 :(得分:2)
您需要将文本作为Formula
的一部分,&
将有助于连接。例如:
import xlwt
wb = xlwt.Workbook()
ws = wb.add_sheet('test')
ws.write(0, 0, xlwt.Formula('"test " & HYPERLINK("http://google.com")'))
wb.save('test.xls')