Python Forum
How to add hyperlink to existing Excel file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to add hyperlink to existing Excel file
#1
Hi,
I have below the main table (both table are (csv):
     grp1                              grp2 
grp  Date      grp1_1  grp1_2          Date       grp2_1 grp2_2 grp2_3   
     
AHJ  20191/7/1 1/3    2/5            20191/7/1  2/5    3/3   2/6
AKL  20191/7/1 2/4    2/6          20191/7/1  1/3    1/5   1/6
HJY  20191/7/1 4/9    3/3          20191/7/1  5/6    3/3   1/11
I have sub table one i have given here (for example)
If I click on any item under (for example) grp1_1, it should link (of pop-up) another table as below:


grp date     
AHJ 2019/7/1 grp1 grp1_1  item1
                          item2
                          item3
[/python]

My extream apologies for that I am very new to this topic, kindly someone help how to do it?
Reply
#2
Hi,

I can be able to insert a hyperlink in a new Excel file, but I want to insert in the existing file.

I use the below code:


import xlsxwriter

# Create a new workbook and add a worksheet
workbook = xlsxwriter.Workbook('hyperlink.xlsx')
worksheet = workbook.add_worksheet('Hyperlinks')

# Format the first column
worksheet.set_column('A:A', 30)

# Add a sample alternative link format.
red_format = workbook.add_format({
    'font_color': 'red',
    'bold':       1,
    'underline':  1,
    'font_size':  12,
})

# Write some hyperlinks
worksheet.write_url('A1', 'http://www.python.org/')  # Implicit format.
worksheet.write_url('A3', 'http://www.python.org/', string='Python Home')
worksheet.write_url('A5', 'http://www.python.org/', tip='Click here')
worksheet.write_url('A7', 'http://www.python.org/', red_format)
worksheet.write_url('A9', 'mailto:[email protected]', string='Mail me')

# Write a URL that isn't a hyperlink
worksheet.write_string('A11', 'http://www.python.org/')
worksheet.write_url('A12', r'D:/Mekala_Backupdata/DataCheck.xlsx',string='mydata')

workbook.close()
It generates a new excel file, but I want to do the same in the existing file and display name should be the original cell value

The existing Excel file is below:

row1 Category date grp1 grp2 grp3
row2 grp1_1 grp1_2 grp2_1 grp2_2 grp2_3 grp3_1
row3 HAY 2019-07-01 3/6 pass fail 3/5 4/11 3/3
row4 PAL 2019-07-02 2/3 pass pass 1/3 4/11 6/15

I just specified the row number here only for clarity,
for example: in row2 column3, it should link to another file as shown below, its cell value should be as the display for a hyperlink, meaning If I click on 3/6 it should link to below file:

HAY 2019-07-01  grp1 
                JKL   0
                OLK   1
                POL   1
                KLA   1
                VAL   0
                power 0
ance.
Kinldy help someone, many thanks in adv
Reply
#3
Hi,

I can be able to insert a hyperlink in a new Excel file, but I want to insert in the existing file.

I use the below code:


import xlsxwriter

# Create a new workbook and add a worksheet
workbook = xlsxwriter.Workbook('hyperlink.xlsx')
worksheet = workbook.add_worksheet('Hyperlinks')

# Format the first column
worksheet.set_column('A:A', 30)

# Add a sample alternative link format.
red_format = workbook.add_format({
    'font_color': 'red',
    'bold':       1,
    'underline':  1,
    'font_size':  12,
})

# Write some hyperlinks
worksheet.write_url('A1', 'http://www.python.org/')  # Implicit format.
worksheet.write_url('A3', 'http://www.python.org/', string='Python Home')
worksheet.write_url('A5', 'http://www.python.org/', tip='Click here')
worksheet.write_url('A7', 'http://www.python.org/', red_format)
worksheet.write_url('A9', 'mailto:[email protected]', string='Mail me')

# Write a URL that isn't a hyperlink
worksheet.write_string('A11', 'http://www.python.org/')
worksheet.write_url('A12', r'D:/Mekala_Backupdata/DataCheck.xlsx',string='mydata')

workbook.close()
It generates a new excel file, but I want to do the same in the existing file and display name should be the original cell value

The existing Excel file is below:

     row1   Category   date        grp1             grp2                    grp3
     row2                          grp1_1 grp1_2    grp2_1   grp2_2 grp2_3  grp3_1 
     row3   HAY      2019-07-01   3/6    pass      fail      3/5   4/11     3/3
     row4   PAL      2019-07-02   2/3    pass      pass      1/3   4/11     6/15
I just specified the row number here only for clarity,
for example: in row2 column3, it should link to another file as shown below, its cell value should be as the display for a hyperlink, meaning If I click on 3/6 it should link to below file:

HAY 2019-07-01  grp1 
                JKL   0
                OLK   1
                POL   1
                KLA   1
                VAL   0
                power 0
ance.
Kinldy help someone, many thanks in adv

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python openyxl not updating Excel file MrBean12 1 329 Mar-03-2024, 12:16 AM
Last Post: MrBean12
  Python best library for Excel reports & review of existing code MasterOfDestr 4 647 Feb-14-2024, 03:39 PM
Last Post: MasterOfDestr
  Copy Paste excel files based on the first letters of the file name Viento 2 438 Feb-07-2024, 12:24 PM
Last Post: Viento
  Search Excel File with a list of values huzzug 4 1,242 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Updating sharepoint excel file odd results cubangt 1 835 Nov-03-2023, 05:13 PM
Last Post: noisefloor
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 1,102 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
  Save and Close Excel File avd88 0 3,051 Feb-20-2023, 07:19 PM
Last Post: avd88
  Trying to access excel file on our sharepoint server but getting errors cubangt 0 815 Feb-16-2023, 08:11 PM
Last Post: cubangt
  Import XML file directly into Excel spreadsheet demdej 0 847 Jan-24-2023, 02:48 PM
Last Post: demdej
  how to read txt file, and write into excel with multiply sheet jacklee26 14 9,971 Jan-21-2023, 06:57 AM
Last Post: jacklee26

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020