0

I need to embed images into an Excel spreadsheet using EEPlus. There 1000's of rows, so embedding these as Pictures is not an option since this file gets generated via a website and the file would be huge and slow to create.

It would be nice if there were a way to set the URL of an image and have it load when the document is opened. Is this possible?

Slee
  • 27,498
  • 52
  • 145
  • 243

1 Answers1

1

If you are staying within the confines of excel, the only way I can think of doing it is with using vba with something like this:

How to get images to appear in Excel given image url.

Can then have it resave itself as non-macroed workbook. Something like this:

//add the macro to call sub that applies the url on open
workbook.Worksheets.Add("newworksheet");

var sb = new StringBuilder();
sb.AppendLine("Private Sub Workbook_SheetCalculate(ByVal Sh As Object)");
sb.AppendLine("    ApplyUrlsSub");
sb.AppendLine("    Application.DisplayAlerts = False");
sb.AppendLine(String.Format("    ActiveWorkbook.SaveAs \"{0}\", xlOpenXMLWorkbook", file.FullName.Replace("xlsm", "xlsx")));
sb.AppendLine("    Application.DisplayAlerts = True");
sb.AppendLine("End Sub");

pck.Workbook.CreateVBAProject();
pck.Workbook.CodeModule.Code = sb.ToString();

(adpated from: EPPlus Pivot Table - Copy Values to New Sheet)

But the user still needs to enable allowing the initial xlsm to run with macros which sould be a problem is there are security concerns.

Ernie S
  • 13,902
  • 4
  • 52
  • 79