open(.xls file, 'w') so that hyperlinks appear
Lemniscate
d_blade8 at hotmail.com
Tue Nov 13 21:53:40 EST 2001
I appreciate the help, and I figured out my problem right before your
post came up. The problem was that I was trying this:
xlApp = win32com.client.Dispatch("Excel.Application")
xlApp.Workbooks.Add()
xlApp.Worksheets(1).Hyperlinks.Add(Range("A5"),
"http://www.thisisatest.com")
which give an error because Range is not defined. What works, and
what I learned, is that I have to, instead, use:
xlApp.Worksheets(1).Hyperlinks.Add(xlApp.Worksheets(1).Range("A5"),
"http://www.thisisatest.com")
Please notice that I was failing to pass in the whole Range
indentifier. Sorry to all, but it seems I was right in my assesment
that it was something simple. (Darn it, I hate being right about
stuff like that!!!). Thanks for all your help and I hope everyone has
a nice day.
Jeff Shannon <jeff at ccvcorp.com> wrote in message news:<3BF16381.A2E07E9A at ccvcorp.com>...
> Lemniscate wrote:
>
> > Okay, my other post should be up soon, but I thought I would throw
> > this out. First off, I should say I am not a VB person, so I have to
> > work at converting VB code into win32client compatible commands.
> > However, the Help File in the MS Excel Help has me stumpted. Here is
> > the page I am using as a basis and afterwards is just a cut and paste
> > of my attempts (at an interactive prompt) to insert a hyper link.
> > Hyperlinks Collection Object
> >
> > ........
> > 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
>
> The trick with VB, is that many times function calls don't require parenthesis to group the parameters. This
> would translate as something like...
>
> # xl.sheet is a Worksheet object...
> xl.sheet.Hyperlinks.Add( xl.sheet.Range('E5'), "http://www.gohere.com")
>
>
> >
> > Okay, here is my interactive attempts. Hopefully, seeing these will
> > help you see what I am doing wrong (I am SURE it is something simple,
> > but it's ticking me off). Also, as a side note, in PythonWin, I
> > cannot run a Commakepy on Excel 9 (I'll add that attempt to the bottom
> > of my code so you can all see what I mean). Thanks a bunch.
>
> You may not have installed the type libraries when you installed Excel. Try installing more Excel
> components--anything mentioning VB or macro facilities (or online help, for that matter...)
>
> >
> > >>> from win32com.client import Dispatch
> > >>> xlApp = Dispatch("Excel.Application")
> > >>> xlApp.Workbooks.Add()
> <COMObject Add>
> > >>> OK = xlApp.Workbooks(1).Sheets(1)
> > >>> OK.Range("B2:C5").Value = "Range Insert"
> > >>> xlApp.Visible = 1
> > >>> xlApp.Hyperlinks.Add.Cells("B5"), 'http://www.gohere.com"
> > Traceback ( File "<interactive input>", line 1
> > xlApp.Hyperlinks.Add.Cells("B5"), 'http://www.gohere.com"
> > ^
> > SyntaxError: invalid token
>
> Judging from the help page you quoted above, Hyperlinks is a property of a sheet, not the app, therefore you
> should (I think) be doing...
>
> OK.Hyperlinks.Add(OK.Cells("B5"), "http://www.gohere.com")
>
> And as I noted previously, Python requires parentheses that VB doesn't.
>
> Once you get the type library installed (and it *should* be on your Office/Excel cd--I had no problem running
> makepy on Excel...) then you can use the COM object browser that's built into PythonWin to examine what functions
> are available, and what parameters they expect--some of the information is kind of cryptic, though, and it helps
> if you have some idea what you're looking for to begin with. ;)
>
> I also *strongly* recommend, if you haven't already, reading Python Programming on Win32 (by Mark Hammond & Andy
> Robinson). It has fairly extensive examples of driving Excel from within Python.
>
> Hope this helps. If you have any more questions, feel free to ask. :)
>
> Jeff Shannon
> Technician/Programmer
> Credit International
More information about the Python-list
mailing list