open(.xls file, 'w') so that hyperlinks appear

Jeff Shannon jeff at ccvcorp.com
Tue Nov 13 19:22:30 EST 2001


Lemniscate wrote:

> Actually, here is the code I am working on now.  .....

Whew.  I'm not very familiar with Tkinter, and as you warned, the code
*is* messy   :)   You might find things easier if you separated this into
several functions/classes--one to set up the GUI, one to parse your input
files, one to drive Excel, etc.  That would make it a bit easier to keep
track of what's going on here.  However, as for the hyperlink problem...

>
>             Pstr = GenericLinkGen.FindTheURL(HLLstr,
> r"http://www.proteome.com/databases/HumanPD/reports/")
>             #Pout.write(Pstr)
>             XL.SetCell(xRow,xCol, Pstr)

I *think* that this is the part that you're trying to create as a
hyperlink.  Presuming that Pstr contains the URL that you want to link to,
and that xRow and xCol are the row/column of the cell you want the
hyperlink to appear in...

Try extending the easyExcel class (from the Python on Win32 book) like
this (I haven't tested it, I'm just going from the docs):

class ExtendedExcel(easyExcel):
    def setHyperlink(self, sheet, row, col, url):
        sht = self.xlBook.Worksheets(sheet)
        sht.Hyperlinks.Add(sht.Cells(row, col),url)

Then, in the above code fragment, replace the setcell call with:

        XL.setHyperlink(1, xRow, xCol, Pstr)

(I notice that your XL method calls don't include the sheet parameter,
unlike the book's version, so you may wish to modify this to treat the
sheet in the same way that you do for setCell(), etc...)

Jeff Shannon
Technician/Programmer
Credit International






More information about the Python-list mailing list