open(.xls file, 'w') so that hyperlinks appear
Lemniscate
d_blade8 at hotmail.com
Tue Nov 13 16:45:54 EST 2001
Actually, here is the code I am working on now. Like I said, I am
tring to learn COM and am, basically, adding methods to the EasyExcel
example given in the Excel chapter of Programming Python on Win32.
Here is what the code I am using now. It uses the same functions and
methods as the previous code, but uses the proper COM methods to
create a Excel file and enter data. The problem I have now, as I
said, is that I cannot insert hyperlinks. I believe I posted my
interactive attempts based on the Excel help files (they should be up
soon so you can see what I mean). Anyways, here is my new code (quick
note: I was working around the problem by creating html files with
the links I wanted and inserting them into an Excel sheet. It
worked/works but is, like you said, not a python thing, plus it makes
things a whole lot messier. I am also in the middle of adding a
Tkinter GUI interface, as well as converting over to
win32com.client.Dispatch methods, so the code is really messy).
Thanks:
if __name__ == "__main__":
opening = Tk()
OFrame = Frame(opening)
OFrame.pack()
Label(opening, text = "This program automates the process of
searching public databases for information on particular genes.\nIt
uses accession numbers to complete this goal.").pack(side = TOP)
Label(opening, text = "Please select the file containing accession
numbers ").pack(side = TOP)
Quitter(opening).pack(side = RIGHT)
fileOpener = Opener(opening)
fileOpener.pack(side = BOTTOM)
opening.title("Open A Text File")
opening.mainloop()
opening.destroy()
file2read = fileOpener.file2open
fin = open(file2read, 'r')
orig = fin.readlines()
fin.close()
print "\nYour request is being processed..."
timetocom = len(orig) * 9.0
print "\nEstimated time of completion: %s" %
time.ctime(time.time() + timetocom)
print "\nPlease wait while your command is completed...\n"
StartTime = time.time()
#fout = open(r"UnigeneLinks.html", 'w')
#App = Dispatch("Excel.Application")
#tout = open(r"accessnums.xls", 'w')
#LLout = open(r"mLocusLinks.html", 'w')
#HLLout = open(r"hLocusLinks.html", 'w')
#Pout = open(r"Proteome.html", 'w')
#OMIMout = open(r'OMIMLinks.html', 'w')
#GenCdsout = open(r'GeneCards.html', 'w')
#tout.write("Accession Number\tUnigene Link\tmLocusLink
Link\tHuman Locus Link\tProteome Link\tOMIM Link\tGeneCards Link\n")
XL = EasyExcel.EasyExcel()
XL.SetCell(1,1,"Accession Number")
XL.SetCell(1,2,"Unigene Link")
XL.SetCell(1,3,"mLocusLink")
XL.SetCell(1,4,"hLocusLink")
XL.SetCell(1,5,"Proteome Link")
XL.SetCell(1,6,"OMIM Link")
XL.SetCell(1,1,"GeneCards Link")
xCol = 1
xRow = 2
global filelen
filelen = 0
for file in orig:
file = getsetnums(file)
if file[0] != '&':
filelen += 1
#tout.write(file)
XL.SetCell(xRow,xCol, file)
xCol +=1
UnigenePage = PrintUnigenePage(file)
#fout.write(makeUnigenePage(file))
XL.SetCell(xRow,xCol, "Unigene Link")
XL.SetComment(xRow, xCol,
StringLoc.UnigeneLink(UnigenePage))
xCol +=1
LLstr = makeLocusLinkPage(UnigenePage)
#LLout.write(LLstr)
XL.SetCell(xRow,xCol, LLstr)
xCol += 1
HLLstr = GenericLinkGen.FindThehLL(LLstr,
r"./LocRpt.cgi?l=")
#HLLout.write(HLLstr)
XL.SetCell(xRow,xCol, HLLstr)
xCol += 1
Pstr = GenericLinkGen.FindTheURL(HLLstr,
r"http://www.proteome.com/databases/HumanPD/reports/")
#Pout.write(Pstr)
XL.SetCell(xRow,xCol, Pstr)
xCol += 1
OMIMstr = GenericLinkGen.FindTheURL(HLLstr,
r"http://www.ncbi.nlm.nih.gov/entrez/dispomim.cgi?id=")
#OMIMout.write(OMIMstr)
XL.SetCell(xRow,xCol, OMIMstr)
xCol += 1
GenCdstr = GenericLinkGen.FindTheURL(HLLstr,
r"http://bioinformatics.weizmann.ac.il/cards-bin/carddisp?")
#GenCdsout.write(GenCdstr)
XL.SetCell(xRow,xCol, GenCdstr)
xCol = 1
xRow += 1
EndTime = time.time()
ElapsedMin = int(math.floor((EndTime - StartTime)/60))
ElapsedSec = int(math.floor((EndTime - StartTime) % 60))
secperfile = (EndTime - StartTime)/filelen
ElapsedStr = "Number of accession numbers processed:
%s\nProcessing Time: %s minutes %s seconds\nEfficiency: %02.1f
seconds\\file" % (filelen, ElapsedMin, ElapsedSec, secperfile)
#tout.write(ElapsedStr)
xRow += 2
XL.SetCell(xRow,xCol, ElapsedStr)
xRow += 1
#tout.write("The program that produced this output is
copyrighted\n***** Copyright © 2001 by DeltaGen, Inc. Program
Design//Implementation: DeltaXpress *****")
XL.SetCell(xRow,xCol, "The program that produced this output is
copyrighted")
xRow += 1
XL.save("AccessNums.xls")
#tout.close()
XL.close()
More information about the Python-list
mailing list