Skip to content

Commit

Permalink
Added fix for #1673 (#1711)
Browse files Browse the repository at this point in the history
  • Loading branch information
OssianEPPlus authored Nov 22, 2024
1 parent 326261d commit 54ee2de
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/EPPlus/Drawing/ExcelPicture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/EPPlusTest/Issues/DrawingIssues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
Expand Down

0 comments on commit 54ee2de

Please sign in to comment.