From 54ee2decf0d24a55c6db4ecde9d25abd564c2500 Mon Sep 17 00:00:00 2001 From: OssianEPPlus <122265629+OssianEPPlus@users.noreply.github.com> Date: Fri, 22 Nov 2024 15:24:03 +0100 Subject: [PATCH] Added fix for #1673 (#1711) --- src/EPPlus/Drawing/ExcelPicture.cs | 13 +++++++++---- src/EPPlusTest/Issues/DrawingIssues.cs | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/EPPlus/Drawing/ExcelPicture.cs b/src/EPPlus/Drawing/ExcelPicture.cs index 2b2e7287d..0a1db96bb 100644 --- a/src/EPPlus/Drawing/ExcelPicture.cs +++ b/src/EPPlus/Drawing/ExcelPicture.cs @@ -62,11 +62,13 @@ internal ExcelPicture(ExcelDrawings drawings, XmlNode node, ExcelGroupShape shap if(picNode != null) { - if (picNode.Attributes["embed", ExcelPackage.schemaRelationships] != null) + + var embedAttr = picNode.Attributes["embed", ExcelPackage.schemaRelationships]; + if (embedAttr != null && string.IsNullOrEmpty(embedAttr.Value) == false) { LocationType = LocationType | PictureLocation.Embed; IPictureContainer container = this; - container.RelPic = drawings.Part.GetRelationship(picNode.Attributes["embed", ExcelPackage.schemaRelationships].Value); + container.RelPic = drawings.Part.GetRelationship(embedAttr.Value); container.UriPic = UriHelper.ResolvePartUri(drawings.UriDrawing, container.RelPic.TargetUri); if (drawings.Part.Package.PartExists(container.UriPic)) @@ -104,11 +106,14 @@ internal ExcelPicture(ExcelDrawings drawings, XmlNode node, ExcelGroupShape shap container.ImageHash = ii.Hash; } - if (picNode.Attributes["link", ExcelPackage.schemaRelationships] != null) + var linkAttr = picNode.Attributes["link", ExcelPackage.schemaRelationships]; + + if (linkAttr != null && string.IsNullOrEmpty(linkAttr.Value) == false ) { LocationType = LocationType | PictureLocation.Link; - LinkedImageRel = drawings.Part.GetRelationship(picNode.Attributes["link", ExcelPackage.schemaRelationships].Value); + LinkedImageRel = drawings.Part.GetRelationship(linkAttr.Value); IPictureContainer container = this; + if(container.RelPic == null && container.UriPic == null) { container.RelPic = LinkedImageRel; diff --git a/src/EPPlusTest/Issues/DrawingIssues.cs b/src/EPPlusTest/Issues/DrawingIssues.cs index b14b6d7ea..f34000ce8 100644 --- a/src/EPPlusTest/Issues/DrawingIssues.cs +++ b/src/EPPlusTest/Issues/DrawingIssues.cs @@ -57,6 +57,20 @@ public void i1640() SaveAndCleanup(package); } } + + [TestMethod] + public void i1673() + { + using (var package = OpenTemplatePackage("i1673.xlsx")) + { + var wb = package.Workbook; + var ws = package.Workbook.Worksheets[0]; + ws.Drawings.Count(); + + SaveAndCleanup(package); + } + } + public void CopyRows(ExcelWorksheet excelWorksheet, int sourceFrom, int sourceTo, int destFrom, int destTo) { for (int i = destFrom; i <= destTo; i++)