Sheetjs: How to create internal links

Created on 13 Jun 2017  路  5Comments  路  Source: SheetJS/sheetjs

I'm trying to generate an XLSX Excel document with JS-XLSX and I can't find a way to create the equivalent of an internal link.

I have this summary page in which I'd like to present clickable links pointing to other sheets.

image

I've tried many combination of cell = {l: {Target: "..", Rel: {Target: "...", Type:"Internal"}}} but it doesn't work. It always ends up as an external hyperlink in the generated document.

I'm using JS-XLSX 0.10.4.

Is this a supported use case?

Write Bug

Most helpful comment

In the internal representation, set a cell's .l key to be an object with Target set to the reference prepended by a # e.g.

ws['A1'].l = { Target: "#Sheet2!A1" } // Link to a cell
ws['A2'].l = { Target: "#Sheet2!A1:D4" } // Link to a range
ws['A3'].l = { Target: "#SomeName" } // Link to a global or same-worksheet defined name
ws['A4'].l = { Target: "#Sheet2!SomeName" } // Link to an out-of-scope defined name

@UzverNumber47 's approach also works

All 5 comments

As a general rule, everything is in the README. If it's not mentioned there, it's either currently unsupported or a bug in the README.

The write logic currently assumes an external hyperlink for every link and every relationship, so at the moment it is not supported. It's relatively simple to fix, we'll try to roll out something in the next release. We will have to add a new flag to the link object.

Would be great to have this feature and also the ability to add VBA code.

You can use formula.
sheet['A1'].f = '=HYPERLINK("#\'Section1\'!A1,"Section 1")';

In the internal representation, set a cell's .l key to be an object with Target set to the reference prepended by a # e.g.

ws['A1'].l = { Target: "#Sheet2!A1" } // Link to a cell
ws['A2'].l = { Target: "#Sheet2!A1:D4" } // Link to a range
ws['A3'].l = { Target: "#SomeName" } // Link to a global or same-worksheet defined name
ws['A4'].l = { Target: "#Sheet2!SomeName" } // Link to an out-of-scope defined name

@UzverNumber47 's approach also works

ws['A1'].l = { Target: "'#SheetName'!A1" } is ok for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dullin picture dullin  路  3Comments

magtuan picture magtuan  路  3Comments

gustavosimil picture gustavosimil  路  3Comments

goxr3plus picture goxr3plus  路  3Comments

thomasledoux1 picture thomasledoux1  路  3Comments