[英]How to add an hyperlink to the content of a cell in excel file?
我从数据库中的Excel文件中导出数据:
response = HttpResponse(mimetype="application/ms-excel")
response['Content-Disposition'] = 'attachment; filename=Countries.xls'
wb = xlwt.Workbook()
ws = wb.add_sheet('Countries')
ws.write(0, 0, 'Country ID')
ws.write(0, 1, 'Country Name')
index = 1
for country in countries:
ws.write(index, 1, country.country_id)
ws.write(index, 1, country.country_name)
index += 1
wb.save(response)
return response
它导出我的excel文件。 如何在此文件的单元格内容中添加超链接? (例如country_name
是在浏览器中打开卡的链接)
worksheet.write(index, 1, xlwt.Formula('HYPERLINK("%s";"TITLE")' % country_name))
从此线程中获取 :
from xlwt import Workbook, Formula
wb = Workbook()
sheet = wb.add_sheet('testing links')
link = 'HYPERLINK("http://stackoverflow.com/"; "SO")'
sheet.write(0, 0, Formula(link))
wb.save('test.xls')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.