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

XSSFSheet.CopySheet - fix null reference error #1332

Closed
wants to merge 2 commits into from

Conversation

Bykiev
Copy link
Collaborator

@Bykiev Bykiev commented May 4, 2024

Closes #346

@Bykiev Bykiev marked this pull request as ready for review May 4, 2024 17:42
@tonyqus
Copy link
Member

tonyqus commented May 4, 2024

Do you figure out why clonedSheet.AddRelation(rel.Id, r) throws exception?

@Bykiev
Copy link
Collaborator Author

Bykiev commented May 5, 2024

I believe it's a copy-paste error, but still not 100% sure in my fix, so, it should be reviewed carefully.

PackageRelationship pr = part.GetPackagePart().GetRelationship(id);
AddRelation(pr, part);

In line 419 the relation is not exists and then it's not checked for null, which cause NRE. Because relation is not exists, we shouldn't call this method at all

@Bykiev
Copy link
Collaborator Author

Bykiev commented May 5, 2024

It seems I was wrong and AddRelation call shouldn't be removed, just added a null check

@cp1319421
Copy link

So do I have a new version to try?@Bykiev

@tonyqus
Copy link
Member

tonyqus commented May 6, 2024

@cp1319421 NPOI doesn't have nightly build. Please pend the next release. It can be a few month later.

@tonyqus tonyqus added this to the NPOI 2.7.1 milestone May 6, 2024
@tonyqus
Copy link
Member

tonyqus commented May 6, 2024

@Bykiev I debug into the code and found that the exception occurs in cloning drawing relationship.

It tried to look for rId1. And drawing1.xml.rels looks like this

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
	<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="../media/image1.png"/>
	<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart" Target="../charts/chart2.xml"/>
	<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart" Target="../charts/chart1.xml"/>
</Relationships>

In other words, rId1 is there. For some reason , it's not found. We may have to dig into this.

@tonyqus tonyqus closed this May 6, 2024
@tonyqus tonyqus removed this from the NPOI 2.7.1 milestone May 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 this pull request may close these issues.

NullReferenceException when copying sheet in some Excel files
3 participants