Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get images to appear in Excel given image url

I'm creating a csv file with one of the columns containing an url of an image (e.g., www.myDomain.com/myImage.jpg).
How I can get Excel to render this image?

like image 459
RayLoveless Avatar asked Jun 10 '11 22:06

RayLoveless


People also ask

How do you display a picture in Excel based on a cell reference?

Using a named range as the source for a linked picture Click Home -> Copy (or Ctrl + C) to copy the cell. Select a different cell (use E2 if working with the example file). Click Home -> Paste (drop-down) -> Linked Picture (alternatively, the Camera Tool is an option). The pasted image will appear.

How do I display hyperlink icons in Excel?

On the Insert tab, select Hyperlink. You can also right-click the cell and then select Hyperlink... on the shortcut menu, or you can press Ctrl+K. Under Display Text:, type the text that you want to use to represent the link. Under Place in this document:, enter the defined name or cell reference.


2 Answers

Dim url_column As Range
Dim image_column As Range

Set url_column = Worksheets(1).UsedRange.Columns("A")
Set image_column = Worksheets(1).UsedRange.Columns("B")

Dim i As Long
For i = 1 To url_column.Cells.Count

  With image_column.Worksheet.Pictures.Insert(url_column.Cells(i).Value)
    .Left = image_column.Cells(i).Left
    .Top = image_column.Cells(i).Top
    image_column.Cells(i).EntireRow.RowHeight = .Height
  End With

Next

As Excel behaviour has apparently changed over years, you might want to specify more parameters to the Insert call explicitly:

For people landing here. Different versions of Excel handle this request differently, Excel 2007 will insert the picture as an object, ie embed it in the workbook. Excel 2010 will insert it as a link, which is bad times if you plan on sending it to anyone. You need to change the insert to specify that it is embedded: Insert(Filename:= <path>, LinkToFile:= False, SaveWithDocument:= True)

like image 74
GSerg Avatar answered Sep 26 '22 20:09

GSerg


On Google Sheets you can add the IMAGE(url) method to your CSV file and it will be rendered (Tested on Google Sheets).

Here is an example:

=IMAGE("http://efdreams.com/data_images/dreams/lion/lion-03.jpg")
like image 32
Sahar Menashe Avatar answered Sep 26 '22 20:09

Sahar Menashe