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 as xlrd fail to read hyperlinks. I would be very thankful if anyone can suggest me some way. I am using xlrd (0.9.2), xlwt(0.7.5) and xlutil1.6.0)
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 workbook 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))
n = "HYPERLINK"
ws.write_merge(row+1, row+1,1, 10, Formula(n +'("C://abc.jpg";"pic")'))
w.save("hyperlinks.xls")
else:
w = Workbook()
ws = w.add_sheet('F')
n = "HYPERLINK"
ws.write_merge(row+1, row+1,1, 10, Formula(n +'("C://abc.jpg";"pic")'))
w.save("hyperlinks.xls")
Thanks for your help!!!