open(.xls file, 'w') so that hyperlinks appear
d_blade8 at hotmail.com
Mon Nov 12 23:15:57 CET 2001
Thanks for the input, I guess I should clarify a little too. I
started learning Python on the recommendation of a friend, for a
problem closely related to the one here. I started writing this
program when I was reading "Learning Python" so the version I'm
posting has me doing a lot of things "the hard way." To create an
Excel file, for example, I just save to an .xls file (as opposed to
using Dispatch from the win32all package, which I didn't know how to
use when I started). The problem now, is that I'm still learning the
whole Win32 thing and interfacing with COM. I am working my way
through it/around it but I still am trying to learn for next time.
Thanks. Here is some of the code (any imported functions I left out
and will just give comments on to save space):
if __name__ == "__main__":
fin = open(r"accessionlist.txt", 'r') #open a file with the info
we want to search and read it
orig = fin.readlines()
fout = open(r"accessionnolinks.xls", 'w') #open a file to write
to, xls makes it an excel file under windows
fout.write("Accession Number\tUnigene Link\n") # write to file,
tabs move between cells
for file in orig: # for each piece of info seperated by a newline
file = getsetnums(file) #get correct format of number (drop
if file != 'X': # A control, if the info fits special
parameters, I know it is invalid and change it to X so I don't deal
with it later
fout.write(makewebpage(file)+ '\n') # create the link
using the accession number and the NCBI cgi Query, returns a hyperlink
What ends up happening is everything works correctly, but I get
but it isn't an actual link until you go into the cell and hit enter
manually. I've thought about just making a macro to do just that, but
that won't teach me how to do it with python, if you know what I mean.
Thanks and I hope that is enough info for you.
Peter Hansen <peter at engcorp.com> wrote in message news:<3BEF67B0.31ED5766 at engcorp.com>...
> Lemniscate wrote:
> > I made a program that takes input from a file (text file with \n
> > splits). I search a public database and find more links (using the
> > urllib.urlopen function). I want to plug these links into Excel and
> > have them as functional links, but all I get is text (a Unicode
> > translation thing, I assume).
> You don't say how you are getting the links into Excel? Are
> you using the win32com package and using the Excel Object Model
> directly from Python? If that's the case, you need to look
> up the relevant information in the Excel docs. I found this tidbit:
> Use the Add method to create a hyperlink and add it to the Hyperlinks collection. The following example creates
> a new hyperlink for cell E5.
> With Worksheets(1)
> .Hyperlinks.Add .Range("E5"), "http://www.gohere.com"
> End With
> > Is there a way to modify the output so
> > that they will show up as links in Excel? I can send my code to
> > anybody who wants to see it (it is big and hairy so I don't want to
> > waste the space here).
> Big and hairy isn't good, but can't you summarize the relevant portions
> and post them? It takes a little work, but ensures the quality
> of the answers is higher...
More information about the Python-list