libxlsxwriter
Loading...
Searching...
No Matches
hyperlinks.c
<< dates_and_times04.c rich_strings.c >>

Example of writing urls/hyperlinks to a worksheet.

/*
* Example of writing urls/hyperlinks with the libxlsxwriter library.
*
* Copyright 2014-2024, John McNamara, jmcnamara@cpan.org
*
*/
#include "xlsxwriter.h"
int main() {
/* Create a new workbook. */
lxw_workbook *workbook = workbook_new("hyperlinks.xlsx");
/* Add a worksheet. */
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
/* Get the default url format (used in the overwriting examples below). */
/* Create a user defined link format. */
lxw_format *red_format = workbook_add_format(workbook);
/* Widen the first column to make the text clearer. */
worksheet_set_column(worksheet, 0, 0, 30, NULL);
/* Write a hyperlink. A default blue underline will be used if the format is NULL. */
worksheet_write_url(worksheet, 0, 0, "http://libxlsxwriter.github.io", NULL);
/* Write a hyperlink but overwrite the displayed string. Note, we need to
* specify the format for the string to match the default hyperlink. */
worksheet_write_url (worksheet, 2, 0, "http://libxlsxwriter.github.io", NULL);
worksheet_write_string(worksheet, 2, 0, "Read the documentation.", url_format);
/* Write a hyperlink with a different format. */
worksheet_write_url(worksheet, 4, 0, "http://libxlsxwriter.github.io", red_format);
/* Write a mail hyperlink. */
worksheet_write_url (worksheet, 6, 0, "mailto:jmcnamara@cpan.org", NULL);
/* Write a mail hyperlink and overwrite the displayed string. We again
* specify the format for the string to match the default hyperlink. */
worksheet_write_url (worksheet, 8, 0, "mailto:jmcnamara@cpan.org", NULL);
worksheet_write_string(worksheet, 8, 0, "Drop me a line.", url_format);
/* Close the workbook, save the file and free any memory. */
workbook_close(workbook);
return 0;
}
void format_set_font_color(lxw_format *format, lxw_color_t color)
Set the color of the font used in the cell.
@ LXW_COLOR_RED
Definition: format.h:218
void format_set_underline(lxw_format *format, uint8_t style)
Turn on underline for the format:
@ LXW_UNDERLINE_SINGLE
Definition: format.h:99
Struct to represent the formatting properties of an Excel format.
Definition: format.h:359
Struct to represent an Excel workbook.
Definition: workbook.h:293
Struct to represent an Excel worksheet.
Definition: worksheet.h:2115
lxw_format * workbook_get_default_url_format(lxw_workbook *workbook)
Get the default URL format used with worksheet_write_url().
lxw_workbook * workbook_new(const char *filename)
Create a new workbook object.
lxw_format * workbook_add_format(lxw_workbook *workbook)
Create a new Format object to formats cells in worksheets.
lxw_error workbook_close(lxw_workbook *workbook)
Close the Workbook object and write the XLSX file.
lxw_worksheet * workbook_add_worksheet(lxw_workbook *workbook, const char *sheetname)
Add a new worksheet to a workbook.
lxw_error worksheet_set_column(lxw_worksheet *worksheet, lxw_col_t first_col, lxw_col_t last_col, double width, lxw_format *format)
Set the properties for one or more columns of cells.
lxw_error worksheet_write_url(lxw_worksheet *worksheet, lxw_row_t row, lxw_col_t col, const char *url, lxw_format *format)
lxw_error worksheet_write_string(lxw_worksheet *worksheet, lxw_row_t row, lxw_col_t col, const char *string, lxw_format *format)
Write a string to a worksheet cell.