How to copy hyperlinks using xlrd, xlwt and xlutils?
Sameer Gupta
sameercool87 at gmail.com
Thu Oct 17 11:15:41 EDT 2013
Hello Everyone!
*Problem:*
I am trying a simple code for writting excel sheet. The program checks if
the Excel sheet already exists, If the file exists, then it append it with
the new data. The problem is I am unable to copy hyperlinks. I would be very
thankful if anyone can suggest me some way.
*Note:* I had used here some default example for hyperlinks. I will be using
this information for my other program where I am suppose to edit excel sheet
with many sheets and every sheet containing hyperlinks at multiple places.
*Code: *
from xlwt import *
import xlrd as xr
import os
from xlutils.copy import copy
name=r"hyperlinks.xls"
if os.path.exists(name)==True:
print "Excel sheet already exists!!!"
cwb=xr.open_workbook(name,formatting_info=True)
w=copy(cwb)
temp=cwb.sheet_by_index(0)
ws=w.get_sheet(0)
row=len(temp.col_values(0))
f = Font()
f.height = 20*72
f.name = 'Verdana'
f.bold = True
f.underline = Font.UNDERLINE_DOUBLE
f.colour_index = 4
h_style = XFStyle()
h_style.font = f
n = "HYPERLINK"
ws.write_merge(row+1, row+1,1, 10, Formula(n +
'("http://www.irs.gov/pub/irs-pdf/f1000.pdf";"f1000.pdf")'), h_style)
ws.write_merge(row+2, row+2, 2, 25, Formula(n +
'("mailto:roman.kiseliov at gmail.com?subject=pyExcelerator-feedback&Body=Hello,%20Roman!";"pyExcelerator-feedback")'),
h_style)
w.save("hyperlinks.xls")
else:
f = Font()
f.height = 20*72
f.name = 'Verdana'
f.bold = True
f.underline = Font.UNDERLINE_DOUBLE
f.colour_index = 4
h_style = XFStyle()
h_style.font = f
w = Workbook()
ws = w.add_sheet('F')
n = "HYPERLINK"
ws.write_merge(1, 1, 1, 10, Formula(n +
'("http://www.irs.gov/pub/irs-pdf/f1000.pdf";"f1000.pdf")'), h_style)
ws.write_merge(2, 2, 2, 25, Formula(n +
'("mailto:roman.kiseliov at gmail.com?subject=pyExcelerator-feedback&Body=Hello,%20Roman!";"pyExcelerator-feedback")'),
h_style)
w.save("hyperlinks.xls")
--
View this message in context: http://python.6.x6.nabble.com/How-to-copy-hyperlinks-using-xlrd-xlwt-and-xlutils-tp5036209.html
Sent from the Python - python-list mailing list archive at Nabble.com.
More information about the Python-list
mailing list