I would like to ask how to retrieve the hyperlink URL which is set on a specific Excel cell using script.
I have already tried "excel.js" and "excelEx.js" which is included in the below Libraries, but could not create it.
https://medini.freshdesk.com/support/solutions/articles/1000273630-scripting-libraries
The current Libraries don't seems to read Hyperlink.
If there are any method to get it, could you please tell me?
Hi,
Not directly tested, but this should hopefully work (as additional function in excel.js):
/* * Excel helper to get hyperlink URL from a cell. */function getHyperlinkOfCell(row, columnIndex) { if (!row) { return undefined; } var cell = row.getCell(columnIndex); if (!cell) { return undefined; } var hyperlink = cell.getHyperlink(); if (hyperlink) { return hyperlink.getAddress(); } return undefined;}
Usage:
var displayText = getTextInCell(row, 2);var url = getHyperlinkOfCell(row, 2);console.log("Text: '{0}', URL: '{1}'", displayText, url);
If you use the poi.js, you should be able to use this:
var link = cell.getHyperlink();var url = link ? link.getAddress() : null;
Regards,
Nils
Just to confirm: POI Cell does support getHyperlink() while simple Excel API used by excel.js does not.
Jan
Dear Nils-san, Jan-san,Thank you for your advice and sorry for my late reply.I would like to share brief feedback regarding Excel hyperlink handling in medini.
cell.getHyperlink().getAddress()
Thanks for posting this to the community, Yusuke, great work!
Note that thre is a separate thread with a similar attempt, basicalyl come up with a library for POI.
See Export of all FMEDA results to Exel : Ansys medini analyze Support
We made some progress there as well (I have to post the latets version) but did not try to replicate the same API but come up with a new one.
Dear Jan-san,
Thank you for your feedback and for pointing me to the other thread!
I will take a look at it.
In our case, the main objective was to keep full compatibility with the existing Excel.js API, since we already have several scripts in productive use.Therefore, I chose to replicate the same interface while replacing the internal implementation with POI.
I am also interested in the alternative approach with a new API and would be happy to compare experiences once the latest version is available.
Thanks again for the reference and for the ongoing improvements.
Yusuke
Thanks Yusuke, very valid point. The "new" API is still a moving target I guess and not fixed.
It started as a community project based on functions that were scripted by the community members, not having compatibility nor a specific API schema in mind. But maybe your point about compatibility should be kept in mind.
Which part of the excel.js have you ported, just the "functions" or also the Callback interface?
I'm sorry for my late reply.
Thanks for the clarification — that makes sense.
In our case, I ported essentially the complete Excel.js layer:
The goal was to ensure that our existing scripts could continue to work without any modification to the calling code. Therefore, I kept the same API surface and only replaced the internal OpenXML-based implementation with a POI-based one.
So far, it behaves transparently from the caller’s perspective.
Excellent! Do you mind posting the result here for the community?
No problem if you cant.
Sorry for my very late reply.
I am sharing a sample project, sample Excel file.
The sample demonstrates the following:
poi_excel.js can be used with the same calling style as the existing excel.js.Cell values can be read via cell.interpretedValue.Hyperlink URLs can be retrieved via:
The attached Excel file is intentionally very simple. It contains only one input cell with a string value and a hyperlink, so the behavior can be checked easily.
The screenshot shows the sample script execution flow and the resulting output in medini.
I hope this can be useful for further improvements or for the community.
Best Regards,