Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed System.InvalidOperationException: 'The hyperlink for cell A1 references relation rId1, but that didn't exist!' #1370

Closed
1 of 5 tasks
htoyama opened this issue Jun 25, 2024 · 1 comment · Fixed by #1441

Comments

@htoyama
Copy link

htoyama commented Jun 25, 2024

NPOI Version

2.7.0

File Type

  • XLSX
  • XLS
  • DOCX
  • XLSM
  • OTHER

Upload the Excel File

Book1.xlsx

Reproduce Steps

workbook.CloneSheet("Sheet1");

Issue Description

System.InvalidOperationException: 'The hyperlink for cell A1 references relation rId1, but that didn't exist!'
RelationshipのIdは、コピー元のワークシートと同じにしないと例外になる。

diff --git a/ooxml/XSSF/UserModel/XSSFWorkbook.cs b/ooxml/XSSF/UserModel/XSSFWorkbook.cs
index 2940dc72..da0981aa 100644
--- a/ooxml/XSSF/UserModel/XSSFWorkbook.cs
+++ b/ooxml/XSSF/UserModel/XSSFWorkbook.cs
@@ -626,7 +626,7 @@ public ISheet CloneSheet(int sheetNum, String newName)
                     if (pr.TargetMode == TargetMode.External)
                     {
                         clonedSheet.GetPackagePart().AddExternalRelationship
-                            (pr.TargetUri.OriginalString, pr.RelationshipType, null);
+                            (pr.TargetUri.OriginalString, pr.RelationshipType, pr.Id);
                     }
                 }
             }
@htoyama htoyama added the bug label Jun 25, 2024
@tonyqus tonyqus added the xlsx label Oct 20, 2024
@tonyqus
Copy link
Member

tonyqus commented Oct 20, 2024

Can you create a PR?

@tonyqus tonyqus added this to the NPOI 2.7.2 milestone Oct 20, 2024
@tonyqus tonyqus modified the milestones: NPOI 2.7.2, NPOI 2.7.3 Nov 9, 2024
tonyqus added a commit to tonyqus/npoi that referenced this issue Nov 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants