Hyperlinks
A cell can hold a clickable link: Excel shows a text and opens an address when the cell is clicked. In sheetsmith a link is a value like any other: a field of type Hyperlink is written as a link by its built-in converter, and any converter can produce a link by returning CellValue.link.
The Hyperlink type
Section titled “The Hyperlink type”package cloud.baldilorenzo.sheetsmith.value;
public record Hyperlink(URI address, String description) { public static Hyperlink of(URI address); public static Hyperlink of(URI address, String description); public static Hyperlink of(String address); public static Hyperlink of(String address, String description); public String text();}| Member | Meaning |
|---|---|
address |
The address the link opens. Not null. |
description |
The text shown in the cell, or null. A blank description counts as missing and is stored as null. |
text() |
The text shown in the cell: the description, or the address when there is none. |
Allowed addresses. The address is checked when the Hyperlink is created, so an invalid address fails in the code that builds the data, before any generation:
| Address | Result |
|---|---|
https://example.com/invoices/2026-101 |
accepted |
http://example.com |
accepted |
mailto:info@example.com |
accepted |
mailto:info@example.com?subject=Report%20Q3 |
accepted: opens the mail client with the subject filled in |
mailto:?subject=Report |
accepted: valid according to RFC 6068, opens the mail client with no recipient |
HTTPS://EXAMPLE.COM/Upper |
accepted: the scheme is not case-sensitive |
ftp://example.com/file |
IllegalArgumentException: hyperlink address ftp://example.com/file has the scheme ftp: the allowed schemes are http, https or mailto |
/docs |
IllegalArgumentException: hyperlink address /docs is not absolute: it needs the scheme http, https or mailto |
https:example.com |
IllegalArgumentException: hyperlink address https:example.com has no host |
https://exa mple.com |
IllegalArgumentException: invalid hyperlink address: Illegal character in authority at index 11: https://exa mple.com |
mailto: |
IllegalArgumentException: invalid hyperlink address: Expected scheme-specific part at index 7: mailto: |
null |
NullPointerException: address |
Only http, https and mailto are allowed: other schemes, such as file, ftp or javascript, would open local resources or run code on the machine of the reader. Links to other sheets or cells of the same workbook are not supported.
The String factories parse the address with URI.create: the address must already be a valid URI, with characters such as spaces percent-encoded. Characters that are valid in a URI but not ASCII, such as accented letters in a path, are accepted: the cell shows the address as written, and the file stores its ASCII form (https://it.wikipedia.org/wiki/Città is stored as https://it.wikipedia.org/wiki/Citt%C3%A0).
A column of links
Section titled “A column of links”@ExcelSheet(title = "Invoices Q3")public record InvoiceRow( @ExcelColumn(header = "Number", order = 10) String number, @ExcelColumn(header = "Amount", order = 20, format = "#,##0.00") BigDecimal amount, @ExcelColumn(header = "Document", order = 30) Hyperlink document, @ExcelColumn(header = "Contact", order = 40) Hyperlink contact) {}
List<InvoiceRow> rows = List.of( new InvoiceRow("2026/101", new BigDecimal("4200.00"), Hyperlink.of("https://billing.example.com/invoices/2026-101", "Open invoice"), Hyperlink.of("mailto:accounts@example.com?subject=Invoice%202026%2F101", "Write to accounts")), new InvoiceRow("2026/102", new BigDecimal("3150.00"), Hyperlink.of("https://billing.example.com/invoices/2026-102"), null));- Each row has its own address and its own text.
- Without a description, the cell shows the address (second row, column
Document). - A null field produces an empty cell, with no link, that keeps its style (second row, column
Contact). mailtoaddresses are written as e-mail links, the others as web links.
Links produced by converters
Section titled “Links produced by converters”CellValue.link(Hyperlink) is a form of cell value like the others, so any converter can produce a link: a field converter, an application converter or a converter bean. A typical use is a domain type that identifies something with a page of its own, such as an order number:
public record OrderNumber(String value) { }
@Component // application converter: every OrderNumber column becomes a link to the orderpublic class OrderNumberConverter implements CellConverter<OrderNumber> {
@Override public CellValue convert(OrderNumber value, ConversionContext context) { String path = URLEncoder.encode(value.value(), StandardCharsets.UTF_8); return CellValue.link(Hyperlink.of("https://shop.example.com/orders/" + path, value.value())); }}- Encode the values placed in an address. A value that contains a space or another character not allowed in a URI makes
Hyperlink.ofthrowIllegalArgumentException; the generation then fails withconverter failedand the sheet, row and field of the value. Encoding the value, as above, avoids it. - What the converter returns decides. A converter that returns
CellValue.linkproduces a link; a converter that returnsCellValue.textproduces a plain text cell, even for a field of typeHyperlink. A field converter on aHyperlinkcolumn can therefore write the address as text, or show a different text with the same address. - Application converters for supertypes win.
Hyperlinkis a record: an application converter registered forRecord, its superclass, or forObject, applies toHyperlinkcolumns too and replaces the built-in converter (section 11.8).
Appearance
Section titled “Appearance”A link cell gets the usual look of a link, a single underline and the colour #0563C1, each only when the styles of the cell leave it unset. The link look is applied after the whole cascade:
| Styles of the cell | Result |
|---|---|
| no font colour, no underline | blue #0563C1 and underlined |
| a font colour, from a named style or from a preset | that colour, underlined |
an underline, Underline.NONE included |
blue, with that underline (none, for NONE) |
| both | exactly as declared |
With the DARK preset, whose data rows have a contrasting white font, links keep the white font and only get the underline, so they stay readable on the dark rows.
LibreOffice Calc shows links with its own colours, blue and underlined, and ignores the font colour and the underline of the cell: declared colours, declared underlines and the white font of DARK are visible only in Excel. With DARK, links are blue on dark blue in LibreOffice. The file is correct.
Limits
Section titled “Limits”| Limit | What happens |
|---|---|
| The text shown, the description or the address when there is none, is longer than 32,767 characters | The generation fails, as for any text (section 14.1). |
| More than 65,530 links in a sheet | The generation fails at the 65,531st link, with sheet, row and field: hyperlink 65531 exceeds the Excel limit of 65530 hyperlinks in a sheet. Excel cannot open a sheet with more links without repairing the file, and the repair removes every link of the sheet. The limit applies to each sheet separately: a workbook can hold several sheets with 65,530 links each. Split the data across sheets, or write the less important links as text. |
| Long addresses | Addresses up to 8,000 characters have been verified to work in Excel. Beyond that, the behaviour depends on Excel and on the browser. |
Links are counted on every column of the sheet; empty cells and text cells are not counted.