EPPlusSoftware / EPPlus

EPPlus-Excel spreadsheets for .NET
https://epplussoftware.com
Other
1.78k stars 273 forks source link

Add Images by Reference in EPPlus #1529

Open simbulanm opened 2 months ago

simbulanm commented 2 months ago

Description:
When using AddPicture or AddPictureAsync in EPPlus, the method generates a significant amount of Large Object Heap (LOH) memory, which can lead to performance issues, especially in web applications where efficient memory usage is critical.

Proposed Solution:
Introduce a new feature to allow images to be added to Excel files by reference, rather than embedding them directly into the file. This can be achieved by enabling the ability to add images using a relative path without the need for existence checks.

image

Benefits:

  1. Reduced Memory Usage: By referencing images instead of embedding them, the LOH memory consumption will be minimized, enhancing performance.
  2. Improved Performance: Especially beneficial for web applications that generate Excel reports, as it will reduce the memory footprint and improve response times.
  3. Simplified Workflow: Allowing images to be added by relative paths without existence checks simplifies the process and reduces the overhead involved in validating image files.

Detailed Requirements:

  1. Add by Reference: Provide an option in the AddPicture and AddPictureAsync methods to add images by reference.
  2. Relative Path Support: Enable the functionality to add images using relative paths without the necessity of checking if the file exists.

Example Usage:


// Adding image by reference with a relative path
worksheet.Drawings.AddPictureByReference("MyImage", "images/logo.png");
swmal commented 2 months ago

Hi @simbulanm,

many thanks for this suggestion - I'll add the enhancement label to it and we will have a look.