File: hyperlink.py

package info (click to toggle)
xlsxwriter 3.1.9-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 56,308 kB
  • sloc: python: 51,511; javascript: 7,768; sh: 284; makefile: 195; perl: 75
file content (37 lines) | stat: -rw-r--r-- 1,145 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
###############################################################################
#
# Example of how to use the XlsxWriter module to write hyperlinks
#
# SPDX-License-Identifier: BSD-2-Clause
# Copyright 2013-2023, John McNamara, jmcnamara@cpan.org
#
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:jmcnamara@cpan.org", string="Mail me")

# Write a URL that isn't a hyperlink
worksheet.write_string("A11", "http://www.python.org/")

workbook.close()