feat(xlsx): inline hyperlinks in data rows (#325)#326
Merged
Conversation
Allow rich hyperlink values directly inside `writeXlsx` `data` row objects,
keyed by a column's `key`, instead of a parallel `cells: Map<"row,col", …>`.
- New `HyperlinkValue` ({ text, hyperlink, tooltip? }) — ExcelJS-compatible shape
- `link(text, hyperlink, tooltip?)` helper exported from hucre and hucre/xlsx
- `#`-prefixed targets become internal references (location)
- `collectHyperlinks` now reads the resolved grid, so links from both `data`
rows and the `cells` map are collected from a single source
- Non-XLSX consumers (ODS writer, pivot source rows) unwrap to scalar text
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #325.
Problem
writeXlsx'scolumns+dataAPI only accepted scalarCellValuefor row values. Hyperlinks with separate display text could only be expressed via the parallelcells: Map<"row,col", …>API — meaning three sources of truth for one logical "Link" column (schema incolumns, value incells, coordinate in a hand-computed"row,col"string). Reordering or inserting columns broke the index math.Solution
Allow rich values inline in
datarows — an ExcelJS-compatible{ text, hyperlink, tooltip? }shape, keyed by the column'skey. Thecellsmap path is fully preserved for backward compatibility.Changes
HyperlinkValuetype + wideneddatatype.CellValueunion is left untouched, so CSV/ODS/formula serialization paths are unaffected.link(text, hyperlink, tooltip?)helper exported from bothhucreandhucre/xlsx. A plain object is also accepted (stays JSON-serializable).#-prefixed targets become internal references (location), e.g."#Sheet2!A1".collectHyperlinksnow reads the resolved grid, so links from both inlinedatarows and thecellsmap are collected from a single source (this also closes the existing gap where acells-map hyperlink was never carried onto theResolvedCell).Design note
Surveyed competing libraries (ExcelJS, SheetJS, write-excel-file).
{ text, hyperlink, tooltip }is the most familiar shape in the ecosystem (ExcelJS) and maps almost 1:1 to hucre's internalHyperlinktype. Issue Option A (inline) was chosen as the core solution; Option B (column-level getter) was left out of scope.Testing
pnpm test: 7472 tests pass (including lint + typecheck).link()helper, tooltip round-trip,#-internal ref, scalar values left untouched, mixed data + cells on the same sheet.data+link()example.🤖 Generated with Claude Code