[BUG] Type for CellHyperlinkValue is wrong, sometimes has nested CellRichTextValue
See original GitHub issueš Bug Report
Lib version: 4.2.0
Steps To Reproduce
- Parse a xlsx file with lots of colours and hyperlinks.
The expected behaviour:
Cells including an hyperlink should follow the CellHyperlinkValue
interface:
export interface CellHyperlinkValue {
text: string;
hyperlink: string;
}
The current behaviour:
Not all cells will match the given interface. We get cells nesting CellRichTextValue
objects inside a linked cell:
{
"text": {
"richText": [
{
"font": {
"underline": true,
"size": 12,
"color": {
"indexed": 17
},
"name": "Calibri"
},
"text": "someone@somewhere.test"
}
]
},
"hyperlink": "mailto:someone@somewhere.test"
}
Possible solution:
It might be enough to change the value for text
on the CellHyperlinkValue
interface. But I am not familiar enough with the innerworkings of ExcelJS to say wether this is enough:
export interface CellHyperlinkValue {
text: string | CellRichTextValue;
hyperlink: string;
}
It might need an even wider type for text
? Maybe straight up CellValue
if anything can be nested?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10 (2 by maintainers)
Top Results From Across the Web
exceljs - bytemeta
[BUG] Issue with web Component Ā· [BUG] Type for CellHyperlinkValue is wrong, sometimes has nested CellRichTextValue.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@skypesky:
I will try to create an XLSX file that I am able to share publicly that shows this problem. Probably later tonight (CET). I havenāt found a clearcut way of creating these types of cells myself, but I should be able to copy one from an existing workbook and anonymise it.
@Wissam-Yelhow:
Be careful with your code there unless you are certain of the origin of your workbook! The same Excel file can contain hyperlink cells with and without nested richtext. If you cast all cell values as you are doing there you may end up casting actual
string
values toCellRichTextValue
which will also break.I like to take the defensive approach. I created a type alias with a fixed
text
and then another where I switch the old hyperlink type for the new one. This way TypeScript can continue to help me in writing code and making sure I cover all bases:With these I can cast a cellās value and work on them knowing the hyperlink values are complete:
Not only can I hover the variable in VSCode to check the type every step of the way, in the
else
block after thetypeof
type narrowing it will also help me write the code as if the typings were always correct:The issue may be related to users who are saving .xlsx files with Apple Numbers, but I havenāt been able to verify this.