Detecting difference between internal and external hyperlinks

Hi,

In excel I can create hyperlinks on cells (or ranges). In the insert hyperlink dialog I have the option to link to an existing document or website or to a location in this document.

When I open this document with Aspose.Cells I can access those links via the hyperlinks collection on the worksheet object and get an Aspose.Cells.Hyperlink object for each hyperlink.

Is there any way to determine if the hyperlink is an external link or an internal link to a location in this workbook?
As far as I can tell, I only have the option to parse the Address property and decide based on the content if this is an internal link or an external link to another document or website.

Are there other options within the Aspose.Cells API to access hyperlinks and determine their type, or do I have to parse the Address property and decide based on my parse results what kind of link I have?

Regards,

Robert Wielink
Sr. Software Engineer
Infoland BV

1 Like

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

I am afraid, there is no property that could determine the type of hyperlink automatically.

Therefore, you will have to parse the Hyperlink.Address property and determine yourself that if it is an external or internal hyperlink.

Normally, external hyperlinks starts from “http://” or “file:////” prefixes while internal hyperlinks are just cell names or they follow the following syntax SheetName!CellName

Not exactly, links to local file or relative links could doesn’t contain scheme at all. In this case it’s hard detect whether it’s external link or internal link to the cell.
Moreover if internal link refers to cell(cells range) with own name, you can’t say at all what is the type of link.

@23W,
Your understanding seems to be right as there is no specific rule to differenciate between the two links. However if it can be done using Excel, please share the steps with us. We will try to provide this feature using Aspose.Cells.

I can’t say about all version of Excel, but looks like all external links always saved separately inside Relationships file “sheet[Number].xml.rels” and have TargetMode attribute with “External” value.
Example:

<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="mailto:kyselgov@gmail.com" TargetMode="External"/>
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="Map1%20(4).mmap" TargetMode="External"/>
<Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" Target="Types.xlsx" TargetMode="External"/>

Internal links on complex data also present here:

<Relationship Id="rId11" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments" Target="../comments1.xml"/>
<Relationship Id="rId10" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing" Target="../drawings/vmlDrawing1.vml"/>

Hyperlinks on worksheet cells or named regions are not save in Relationships collections but are keeped inside sheet file hyperlink collection and do not contain relationship Id:

<hyperlinks>
     <!-- All hyperlinks with external type have Relationship Id of Relationship record where link's url is saved.  -->
    <hyperlink ref="G2" r:id="rId1" xr:uid="{045D6E3D-92FC-4565-8733-F30B5F07EA11}"/>
    <hyperlink ref="G4" r:id="rId2" xr:uid="{D0E0C6FB-DA9F-47DF-933E-AA376B841251}"/>
    <hyperlink ref="G3" r:id="rId3" display="s" xr:uid="{C8BBFB16-7AD5-4D9E-82E4-3D51B555EECD}"/>
    <hyperlink ref="G5" r:id="rId4" xr:uid="{9B71B712-7F7D-4F01-8CF5-307B3D254852}"/>
     <!-- G6 contains link on cell B2 from sheet  'She et1!' -->
    <hyperlink ref="G6" location="'She et1!'!B2" display="B2" xr:uid="{76D356C3-127B-4EFB-8290-633AF9594BF4}"/>
    <hyperlink ref="F2" r:id="rId5" xr:uid="{DBD663C1-1CDC-4A7C-97AB-57B5628CF697}"/>
    <hyperlink ref="F3" r:id="rId6" xr:uid="{55794A44-C157-43B5-84D6-19357E606D63}"/>
    <hyperlink ref="F4" r:id="rId7" xr:uid="{1EE1B9D1-B137-487F-8CF7-F239C93360A2}"/>
    <hyperlink ref="F5" r:id="rId8" display="Map Link" xr:uid="{A78619BB-679E-42C7-B411-98774F0247FB}"/>
     <!-- G7 contains link on named range MYCELL -->
    <hyperlink ref="G7" location="MYCELL" display="MYCELL" xr:uid="{936519AB-4F2D-4F51-9FEB-32C90A100B6E}"/>
</hyperlinks>

So, I think you have all required information to detect following types of link:

  • External,
  • Internal,
  • Link on cell or named range.

It would be nice if you add it in Aspose Cell API

@23W,
Thank you for providing this detail. We were able to understand the requirement but we need to look into it more. We have logged the issue in our database for investigation and for implementation (if possible). Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSNET-46822 – Detecting difference between internal and external hyperlinks
1 Like

@23W,

Please try our latest version/fix: Aspose.Cells for .NET v19.7.1 (attached)

Your issue should be fixed in it. Please try Hyperlink.LinkType attribute.

Let us know your feedback.
Aspose.Cells19.7.1 For .Net2_AuthenticodeSigned.Zip (4.9 MB)
Aspose.Cells19.7.1 For .Net4.0.Zip (4.9 MB)

Wow! Such quick work!
But I can’t test it. I’m receiving this error message “Sorry, this file is private. Only visible to topic owner and staff members.” when try to download your links.

@23W,

Since you are not the owner of the thread, so you might not download the attachments. Please create a new thread and ask for the new fix, we will share the fix in your newer thread for your requirements.

Done.

@23W,

Fix posted in your thread.

The issues you have found earlier (filed as CELLSNET-46822) have been fixed in Aspose.Cells for .NET v19.8. This message was posted using BugNotificationTool from Downloads module by Amjad_Sahi