Skip to content

Commit 10fa4f1

Browse files
authored
Merge pull request #578 from sampsonye/fix-hyperlink
fix #543 The given key 'rId1' was not present in the dictionary
2 parents 76adc09 + b1a8f7b commit 10fa4f1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/EPPlus/EPPlus/ExcelWorksheet.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,7 @@ private static bool ReadXmlReaderUntil(XmlReader xr, string nodeText, string alt
11711171
private void LoadHyperLinks(XmlReader xr)
11721172
{
11731173
if (!ReadUntil(xr, "hyperlinks", "rowBreaks", "colBreaks")) return;
1174+
var rIdCache = new Dictionary<string, Uri>();
11741175
while (xr.Read())
11751176
{
11761177
if (xr.LocalName == "hyperlink")
@@ -1181,7 +1182,10 @@ private void LoadHyperLinks(XmlReader xr)
11811182
if (xr.GetAttribute("id", ExcelPackage.schemaRelationships) != null)
11821183
{
11831184
var rId = xr.GetAttribute("id", ExcelPackage.schemaRelationships);
1184-
var uri = Part.GetRelationship(rId).TargetUri;
1185+
if (!rIdCache.TryGetValue(rId,out var uri))
1186+
{
1187+
uri = Part.GetRelationship(rId).TargetUri;
1188+
}
11851189
if (uri.IsAbsoluteUri)
11861190
{
11871191
try
@@ -1199,6 +1203,7 @@ private void LoadHyperLinks(XmlReader xr)
11991203
}
12001204
hl.RId = rId;
12011205
Part.DeleteRelationship(rId); //Delete the relationship, it is recreated when we save the package.
1206+
rIdCache[rId] = uri;
12021207
}
12031208
else if (xr.GetAttribute("location") != null)
12041209
{

0 commit comments

Comments
 (0)