- Python XlsxWriter - VBA Macro
- Python XlsxWriter - Working with Pandas
- Python XlsxWriter - Cell Comments
- Python XlsxWriter - Header & Footer
- Python XlsxWriter - Page Setup
- Python XlsxWriter - Insert Image
- Python XlsxWriter - Textbox
- Python XlsxWriter - Hide/Protect Worksheet
- Python XlsxWriter - Freeze & Split Panes
- Python XlsxWriter - Outlines & Grouping
- Python XlsxWriter - Data Validation
- Python XlsxWriter - Sparklines
- Python XlsxWriter - Pie Chart
- Python XlsxWriter - Line Chart
- Python XlsxWriter - Bar Chart
- Python XlsxWriter - Chart Legends
- Python XlsxWriter - Chart Formatting
- Python XlsxWriter - Adding Charts
- Python XlsxWriter - Conditional Formatting
- Python XlsxWriter - Hyperlinks
- Python XlsxWriter - Border
- Python XlsxWriter - Number Formats
- Python XlsxWriter - Fonts & Colors
- Python XlsxWriter - Applying Filter
- Python XlsxWriter - Tables
- Python XlsxWriter - Date and Time
- Python XlsxWriter - Formula & Function
- Python XlsxWriter - Defined Names
- Python XlsxWriter - Cell Notation & Ranges
- Python XlsxWriter - Important classes
- Python XlsxWriter - Hello World
- Python XlsxWriter - Environment Setup
- Python XlsxWriter - Overview
- Python XlsxWriter - Home
Python XlsxWriter Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Python XlsxWriter - Hyperpnks
A hyperpnk is a string, which when cpcked, takes the user to some other location, such as a URL, another worksheet in the same workbook or another workbook on the computer. Worksheet class provides write_url() method for the purpose. Hyperpnks can also be placed inside a textbox with the use of url property.
First, let us learn about write_url() method. In addition to the Cell location, it needs the URL string to be directed to.
import xlsxwriter workbook = xlsxwriter.Workbook( hello.xlsx ) worksheet = workbook.add_worksheet() worksheet.write_url( A1 , https://www.tutorialspoint.com/index.htm ) workbook.close()
This method has a few optional parameters. One is a Format object to configure the font, color properties of the URL to be displayed. We can also specify a tool tip string and a display text foe the URL. When the text is not given, the URL itself appears in the cell.
Example
Different types of URLs supported are http://, https://, ftp:// and mailto:. In the example below, we use these URLs.
import xlsxwriter workbook = xlsxwriter.Workbook( hello.xlsx ) worksheet = workbook.add_worksheet() worksheet.write_url( A1 , https://www.tutorialspoint.com/index.htm ) worksheet.write_url( A3 , http://localhost:8080 ) worksheet.write_url( A5 , ftp://www.python.org ) worksheet.write_url( A7 , mailto:dummy@abc.com ) workbook.close()
Output
Run the above code and open the hello.xlsx file using Excel.
Example
We can also insert hyperpnk to either another workskeet in the same workbook, or another workbook. This is done by prefixing with internal: or external: the local URIs.
import xlsxwriter workbook = xlsxwriter.Workbook( hello.xlsx ) worksheet = workbook.add_worksheet() worksheet.write_url( A1 , internal:Sheet2!A1 , string="Link to sheet2", tip="Cpck here") worksheet.write_url( A4 , "external:c:/test/testpnk.xlsx", string="Link to other workbook") workbook.close()
Output
Note that the string and tip parameters are given as an alternative text to the pnk and tool tip. The output of the above program is as given below −
Advertisements