Hyperlinks and Tooltips
File Format Support (click to show)
Spreadsheet hyperlinks are clickable references to other locations. They serve
the same role as the HTML <a> tag.
Spreadsheet applications can process "internal" (cells, ranges, and defined names) and "external" (websites, email addresses, and local files) references.
SheetJS hyperlink objects are stored in the l key of cell objects. Hyperlink
objects include the following fields:
Target(required) describes the reference.Tooltipis the tooltip text. Tooltips are shown when hovering over the text.
For example, the following snippet creates a link from cell A1 to
https://sheetjs.com with the tip "Find us @ SheetJS.com!":
/* create worksheet with cell A1 = "https://sheetjs.com" */
var ws = XLSX.utils.aoa_to_sheet([["https://sheetjs.com"]]);
/* add hyperlink */
ws["A1"].l = {
Target: "https://sheetjs.com",
Tooltip: "Find us @ SheetJS.com!"
};

Following traditional software, hyperlinks are applied to entire cell objects. Some formats (including HTML) attach links to text spans. The parsers apply the first link to the entire cell. Writers apply links to the entire cell text.
Excel does not automatically style hyperlinks. They will be displayed using the default cell style.
SheetJS Pro Basic includes support for general hyperlink styling.
External Hyperlinks​
Spreadsheet software will typically launch other programs to handle external hyperlinks. For example, clicking a "Web Link" will open a new browser window.
Web Links​
HTTP and HTTPS links can be used directly:
ws["A2"].l = { Target: "https://docs.sheetjs.com/docs/csf/features/hyperlinks#web-links" };
ws["A3"].l = { Target: "http://localhost:7262/yes_localhost_works" };
Live Example (click to hide)
/* The live editor requires this function wrapper */
function ExportSimpleLink() { return ( <button onClick={() => {
/* Create worksheet */
var ws = XLSX.utils.aoa_to_sheet([ [ "Link", "No Link" ] ]);
/* Add link */
ws["A1"].l = {
Target: "https://sheetjs.com",
Tooltip: "Find us @ SheetJS.com!"
};
/* Export to file (start a download) */
var wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
XLSX.writeFile(wb, "SheetJSSimpleLink.xlsx");
}}><b>Export XLSX!</b></button> ); }
Mail Links​
Excel also supports mailto email links with subject line:
ws["A4"].l = { Target: "mailto:ignored@dev.null" };
ws["A5"].l = { Target: "mailto:ignored@dev.null?subject=Test Subject" };
Live Example (click to show)
Local Links​
Links to absolute paths should use the file:// URI scheme:
ws["B1"].l = { Target: "file:///SheetJS/t.xlsx" }; /* Link to /SheetJS/t.xlsx */
ws["B2"].l = { Target: "file:///c:/SheetJS.xlsx" }; /* Link to c:\SheetJS.xlsx */
Links to relative paths can be specified without a scheme:
ws["B3"].l = { Target: "SheetJS.xlsb" }; /* Link to SheetJS.xlsb */
ws["B4"].l = { Target: "../SheetJS.xlsm" }; /* Link to ../SheetJS.xlsm */
Relative Paths have undefined behavior in the SpreadsheetML 2003 format. Excel
2019 will treat a ..\ parent mark as two levels up.
Internal Hyperlinks​
Links where the target is a cell or range or defined name in the same workbook ("Internal Links") are marked with a leading hash character:
ws["C1"].l = { Target: "#E2" }; /* Link to cell E2 */
ws["C2"].l = { Target: "#Sheet2!E2" }; /* Link to cell E2 in sheet Sheet2 */
ws["C3"].l = { Target: "#SheetJSDName" }; /* Link to Defined Name */
Live Example (click to show)
Some third-party tools like Google Sheets do not correctly parse hyperlinks in XLSX documents. A workaround was added in library version 0.18.12.
Tooltips​
Tooltips are attached to hyperlink information. There is no way to specify a tooltip without assigning a cell link.
Excel has an undocumented tooltip length limit of 255 characters.
Writing longer tooltips is currently permitted by the library but the generated files will not open in Excel.
HTML​
The HTML DOM parser1 will process <a> links in the table.
Live Example (click to hide)
This example uses table_to_book to generate a SheetJS workbook object from a
HTML table. The hyperlink in the second row will be parsed as a cell-level link.
/* The live editor requires this function wrapper */
function ExportHyperlink() {
/* Callback invoked when the button is clicked */
const xport = React.useCallback(() => {
/* Create worksheet from HTML DOM TABLE */
const table = document.getElementById("TableLink");
const wb = XLSX.utils.table_to_book(table);
/* Export to file (start a download) */
XLSX.writeFile(wb, "SheetJSHTMLHyperlink.xlsx");
});
return ( <>
<button onClick={xport}><b>Export XLSX!</b></button>
<table id="TableLink"><tbody><tr><td>
Do not click here, for it is link-less.
</td></tr><tr><td>
<a href="https://sheetjs.com">Click here for more info</a>
</td></tr></tbody></table>
</> );
}
The HTML writer2 will generate <a> links.
Live Example (click to hide)
This example creates a worksheet where A1 has a link and B1 does not. The
sheet_to_html function generates an HTML table where the topleft table cell
has a standard HTML link.
/* The live editor requires this function wrapper */
function ExportALinks() {
const [ __html, setHTML ] = React.useState("");
React.useEffect(() => {
/* Create worksheet */
var ws = XLSX.utils.aoa_to_sheet([ [ "Link", "No Link" ] ]);
/* Add link */
ws["A1"].l = {
Target: "https://sheetjs.com",
Tooltip: "Find us @ SheetJS.com!"
};
/* Generate HTML */
setHTML(XLSX.utils.sheet_to_html(ws));
}, []);
return ( <div dangerouslySetInnerHTML={{__html}}/> );
}
Miscellany​
Extract all links from a file (click to show)
Footnotes​
-
The primary SheetJS DOM parsing methods are
table_to_book,table_to_sheet, andsheet_add_dom↩ -
HTML strings can be written using
bookType: "html"in thewriteorwriteFilemethods or by using the dedicatedsheet_to_htmlutility function ↩