FAQ
I want to create a hyperlink in my excel sheet using python such that when you click on that link (which is a file name (html file)), the file automatically opens. This file is present in the same folder in which the python code file is present.

I am using xlwt module





link= 'abcd.html'
sheet.write(x, y, link, format_style)



x: row y :col



Thanks,

Pratik

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101014/65d5e32b/attachment.html>

Search Discussions

  • Chris Rebert at Oct 13, 2010 at 9:15 pm

    On Wed, Oct 13, 2010 at 1:57 PM, Pratik Khemka wrote:
    I want to create a hyperlink in my excel sheet using python such that when
    you click on that link (which is?a file name (html file)), the file
    automatically opens. This file is present in the same folder in which the
    python code file is present.
    I am using xlwt module
    You might consider asking on their newsgroup then:
    http://groups.google.com/group/python-excel

    Cheers,
    Chris
    --
    "Python Problem solver"; Quite a complementary moniker for the list there.
  • Emile van Sebille at Oct 13, 2010 at 9:19 pm
    On 10/13/2010 1:57 PM Pratik Khemka said...
    I want to create a hyperlink in my excel sheet using python such that when you click on that link (which is a file name (html file)), the file automatically opens. This file is present in the same folder in which the python code file is present.

    I am using xlwt module





    link= 'abcd.html'
    sheet.write(x, y, link, format_style)

    Hmmm... my excel does that automagically when I
    type "http://xx.yy.zz/word.html into a cell.

    What happens when you use "http://a.b.c/abcd.html"?

    Emile
  • Pratik Khemka at Oct 13, 2010 at 10:13 pm
    This file is present on my hardrive..This file is present in the same folder in which the python code file is present...so http: wont work..

    To: python-list at python.org
    From: emile at fenx.com
    Subject: Re: Hyperlink to a file using python
    Date: Wed, 13 Oct 2010 14:19:36 -0700

    On 10/13/2010 1:57 PM Pratik Khemka said...
    I want to create a hyperlink in my excel sheet using python such that when you click on that link (which is a file name (html file)), the file automatically opens. This file is present in the same folder in which the python code file is present.

    I am using xlwt module





    link= 'abcd.html'
    sheet.write(x, y, link, format_style)

    Hmmm... my excel does that automagically when I
    type "http://xx.yy.zz/word.html into a cell.

    What happens when you use "http://a.b.c/abcd.html"?

    Emile

    --
    http://mail.python.org/mailman/listinfo/python-list
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20101014/bca1e8e0/attachment.html>
  • Chris Rebert at Oct 13, 2010 at 10:19 pm

    To: python-list at python.org
    From: emile at fenx.com
    Subject: Re: Hyperlink to a file using python
    Date: Wed, 13 Oct 2010 14:19:36 -0700

    On 10/13/2010 1:57 PM Pratik Khemka said...
    I want to create a hyperlink in my excel sheet using python such that
    when you click on that link (which is a file name (html file)), the file
    automatically opens. This file is present in the same folder in which the
    python code file is present.

    I am using xlwt module

    link= 'abcd.html'
    sheet.write(x, y, link, format_style)
    Hmmm... my excel does that automagically when I
    type "http://xx.yy.zz/word.html into a cell.

    What happens when you use "http://a.b.c/abcd.html"?
    On Wed, Oct 13, 2010 at 3:13 PM, Pratik Khemka wrote:
    This file is present on my hardrive..This file is present in the same folder
    in which the python code file is present...so http: wont work..
    Have you tried a file:/// URI?
    http://en.wikipedia.org/wiki/File_URI_scheme

    Cheers,
    Chris
  • Pratik Khemka at Oct 14, 2010 at 5:54 pm
    I think I did not frame the question in a proper manner..

    I want to open pratik.html which is there in the same folder as the python program. I do not want to specify the path like you can see below in the code (blue) c:\Documents and Settings\My Documents..The reason for this is that I want the code to be portable , ie others should also be able to run the program on their computers in whichever folder they want to. In this situation the code wont work on other computers due to the path name specified.

    Currently I am using this code below :
    sheet.write(4,3,"file:///c:\Documents and Settings\My Documents\pratik.html",hyperlink_style)

    What I want to know is that if there is a way to remove the blue part (path to file)..I think it should be possible because the file is present in the same folder as the python program..
    Currently the hyperlink only works if the blue part is also there..I am sorry if this question probably does not belong to this group and maybe belongs more to the excel group.

    Thanks a lot for all the help..I really aprreciate it..
    Pratik

    Date: Wed, 13 Oct 2010 15:19:54 -0700
    Subject: Re: Hyperlink to a file using python
    From: clp2 at rebertia.com
    To: pratikkhemka at hotmail.com
    CC: python-list at python.org
    To: python-list at python.org
    From: emile at fenx.com
    Subject: Re: Hyperlink to a file using python
    Date: Wed, 13 Oct 2010 14:19:36 -0700

    On 10/13/2010 1:57 PM Pratik Khemka said...
    I want to create a hyperlink in my excel sheet using python such that
    when you click on that link (which is a file name (html file)), the file
    automatically opens. This file is present in the same folder in which the
    python code file is present.

    I am using xlwt module

    link= 'abcd.html'
    sheet.write(x, y, link, format_style)
    Hmmm... my excel does that automagically when I
    type "http://xx.yy.zz/word.html into a cell.

    What happens when you use "http://a.b.c/abcd.html"?
    On Wed, Oct 13, 2010 at 3:13 PM, Pratik Khemka wrote:
    This file is present on my hardrive..This file is present in the same folder
    in which the python code file is present...so http: wont work..
    Have you tried a file:/// URI?
    http://en.wikipedia.org/wiki/File_URI_scheme

    Cheers,
    Chris
    -------------- next part --------------
    An HTML attachment was scrubbed...
    URL: <http://mail.python.org/pipermail/python-list/attachments/20101014/d59101a4/attachment-0001.html>
  • MRAB at Oct 14, 2010 at 6:36 pm

    On 14/10/2010 18:54, Pratik Khemka wrote:
    I think I did not frame the question in a proper manner..

    I want to open pratik.html which is there in the same folder as the
    python program. I do not want to specify the path like you can see below
    in the code (blue) *_c:\Documents_ and Settings\My Documents..*The
    reason for this is that I want the code to be portable , ie others
    should also be able to run the program on their computers in whichever
    folder they want to. In this situation the code wont work on other
    computers due to the path name specified.

    Currently I am using this code below :
    *sheet.write(4,3,"**file:///c:\Documents** and Settings\My
    Documents\pratik.html",hyperlink_style)*
    **
    What I want to know is that if there is a way to remove the blue part
    (path to file)..I think it should be possible because the /file is
    present in the same folder as the python program/..
    Currently the hyperlink only works if the blue part is also there..I am
    sorry if this question probably does not belong to this group and maybe
    belongs more to the excel group.

    Thanks a lot for all the help..I really aprreciate it..
    [snip]
    Try a relative hyperlink like "file:pratik.html".
  • Dave Angel at Oct 14, 2010 at 8:11 pm

    On 2:59 PM, Pratik Khemka wrote:
    I think I did not frame the question in a proper manner..

    I want to open pratik.html which is there in the same folder as the python program. I do not want to specify the path like you can see below in the code (blue) c:\Documents and Settings\My Documents..The reason for this is that I want the code to be portable , ie others should also be able to run the program on their computers in whichever folder they want to. In this situation the code wont work on other computers due to the path name specified.

    Currently I am using this code below :
    sheet.write(4,3,"file:///c:\Documents and Settings\My Documents\pratik.html",hyperlink_style)

    What I want to know is that if there is a way to remove the blue part (path to file)..I think it should be possible because the file is present in the same folder as the python program..
    Currently the hyperlink only works if the blue part is also there..I am sorry if this question probably does not belong to this group and maybe belongs more to the excel group.

    Thanks a lot for all the help..I really aprreciate it..
    Pratik
    (You top-posted, so I had to remove all the earlier stuff which is now
    out of order.)

    I'm assuming you're generating this spreadsheet from python. So if you
    know what the format of the string is, generate it accordingly. You can
    use __file__ to get full the path of the python script, use
    os.path.dirname() on it, and use os.path.join() to combine it with the
    "pratik.html". You might also need abspath().

    Once the spreadsheet has been written, it's not portable to other
    machines. But fixing that would be an Excel problem, and you're asking
    in python forum.

    DaveA

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedOct 13, '10 at 8:57p
activeOct 14, '10 at 8:11p
posts8
users5
websitepython.org

People

Translate

site design / logo © 2022 Grokbase