Skip to content

Commit

Permalink
Merge pull request #578 from sampsonye/fix-hyperlink
Browse files Browse the repository at this point in the history
fix #543 The given key 'rId1' was not present in the dictionary
  • Loading branch information
xl-wenqiang authored Oct 28, 2024
2 parents 76adc09 + b1a8f7b commit 10fa4f1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/EPPlus/EPPlus/ExcelWorksheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,7 @@ private static bool ReadXmlReaderUntil(XmlReader xr, string nodeText, string alt
private void LoadHyperLinks(XmlReader xr)
{
if (!ReadUntil(xr, "hyperlinks", "rowBreaks", "colBreaks")) return;
var rIdCache = new Dictionary<string, Uri>();
while (xr.Read())
{
if (xr.LocalName == "hyperlink")
Expand All @@ -1181,7 +1182,10 @@ private void LoadHyperLinks(XmlReader xr)
if (xr.GetAttribute("id", ExcelPackage.schemaRelationships) != null)
{
var rId = xr.GetAttribute("id", ExcelPackage.schemaRelationships);
var uri = Part.GetRelationship(rId).TargetUri;
if (!rIdCache.TryGetValue(rId,out var uri))
{
uri = Part.GetRelationship(rId).TargetUri;
}
if (uri.IsAbsoluteUri)
{
try
Expand All @@ -1199,6 +1203,7 @@ private void LoadHyperLinks(XmlReader xr)
}
hl.RId = rId;
Part.DeleteRelationship(rId); //Delete the relationship, it is recreated when we save the package.
rIdCache[rId] = uri;
}
else if (xr.GetAttribute("location") != null)
{
Expand Down

0 comments on commit 10fa4f1

Please sign in to comment.