diff --git a/.changeset/support_clickable_link_in_export.md b/.changeset/support_clickable_link_in_export.md new file mode 100644 index 000000000..8714096d6 --- /dev/null +++ b/.changeset/support_clickable_link_in_export.md @@ -0,0 +1,28 @@ +# Release Notes: contexture-export + +## [Patch] - Hyperlink Support for Excel Exports + +### Overview + +This patch introduces a new feature for Excel-type exports where cells can now be rendered as clickable hyperlinks. This is achieved by providing a specific metadata structure that the exporter converts into native Excel formulas. + +### New Features + +- **Dynamic Excel Hyperlinks**: Cells can now display a custom text label while linking to a specific URL. +- **Metadata-Driven Rendering**: The system identifies links via the `__isHyperlink` flag within the `meta` object. +- **Display Label Mapping**: The `__alias` property is used as the visible display label for the provided URL. +- **Formula Safety**: The exporter automatically handles double-quote escaping to ensure the Excel `HYPERLINK` formula remains valid. + +### Data Structure Requirements + +To render a cell as a link, the record data for that cell must follow this structure: + +```json +{ + "url": "https://example.com/detail/123", + "meta": { + "__isHyperlink": true, + "__alias": "Click to Open Link" + } +} +``` diff --git a/packages/export/package.json b/packages/export/package.json index e682d610f..6cd5f8565 100644 --- a/packages/export/package.json +++ b/packages/export/package.json @@ -1,6 +1,6 @@ { "name": "contexture-export", - "version": "1.3.2", + "version": "1.3.3", "description": "Contexture Exports", "type": "module", "exports": { diff --git a/packages/export/src/excel.js b/packages/export/src/excel.js index 6e4edb2d7..2b14e0408 100644 --- a/packages/export/src/excel.js +++ b/packages/export/src/excel.js @@ -8,6 +8,14 @@ let headerBackgroundColor = '#999999' let indexColumnBackgroundColor = '#bbbbbb' const convertToExcelCell = (value, index) => { + if (value?.meta?.__isHyperlink) { + const displayValue = value?.meta?.__alias || value?.url || 'Link' + return { + value: `HYPERLINK("${value?.url}", "${displayValue}")`, + type: 'Formula', + wrap: true, + } + } return { wrap: true, value: value ? `${value}` : ``,