Connecting Tech Pros Worldwide Forums | Help | Site Map

Embed an image in an .xls Excel sheet

code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,156
#1: Jun 4 '09
I have written scripts that generate price lists on a .xls sheet.
The price lists are written in HTML so I can embed an image easily using <img src .........

But when the .xls leaves the local folder, ie emailed out,
it can no longer 'see' the image because the src path is no longer valid.

How are images permanently embedded in .xls? or HTML for that matter.
The code behind is HTML so am I missing a trick somewhere?

Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,990
#2: Jun 4 '09

re: Embed an image in an .xls Excel sheet


You can embed images into a <img> tag by doing:
Expand|Select|Wrap|Line Numbers
  1. <img src="data:[mime-type],[data]" alt="" />
For example, to display a 16x16 PNG filled with red (borrowed from the W3C html validation site):
Expand|Select|Wrap|Line Numbers
  1. <img alt="Red square" src="data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%10%00%00%00%10%08%02%00%00%00%90%91h6%00%00%00%19IDAT(%91c%BCd%AB%C2%40%0A%60%22I%F5%A8%86Q%0DCJ%03%00%DE%B5%01S%07%88%8FG%00%00%00%00IEND%AEB%60%82" />
All modern browsers and email clients should be able to understand this.
IE versions 7 and up should be able to handle it to.
Not sure about Outlook tho.
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,156
#3: Jun 4 '09

re: Embed an image in an .xls Excel sheet


Ah I see.
The example I am looking at uses VML and seems to designate a path
Expand|Select|Wrap|Line Numbers
  1. if gte vml 1]><v:shapetype
  2.    id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t"
  3.    path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f">
Then the image source quotes only the directory and the file
Expand|Select|Wrap|Line Numbers
  1. <img width=800 height=190
  2.   src="Pricelist-0409_files/image002.jpg" v:shapes="Picture_x0020_5">
I assume what is happening here is the url is embedded and the image is being downloaded from a remote server
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,990
#4: Jun 4 '09

re: Embed an image in an .xls Excel sheet


I don't know the first thing about VML, so I can't really say much about that.

Nor about Excel documents, really, but I do know that embedding images, the way I did, is not very popular in emails because Outlook's HTML rendering engine is behind that standards by a couple of decades, and therefore lacks the ability to render them correctly.

So unless this VML markup language has some other way of embedding them, it really only leaves it using remote URLs.
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,156
#5: Jun 4 '09

re: Embed an image in an .xls Excel sheet


Quote:
I don't know the first thing about VML
Me neither!
I may use remote URLs until I can figure out this VML.
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,990
#6: Jun 4 '09

re: Embed an image in an .xls Excel sheet


Quote:

Originally Posted by code green View Post

Me neither!
I may use remote URLs until I can figure out this VML.

I would check out SVG instead.

I don't know that one either, but it was apparently developed by the W3C after M$ and several others tried to get their version of this standardized.

http://en.wikipedia.org/wiki/Vector_Markup_Language
Quote:

Originally Posted by Wikipedia

VML was submitted as a proposed standard to the W3C in 1998 by Microsoft, Macromedia, and others.[1]
Around the same time other competing W3C submissions were received in the area of web vector graphics, such as PGML from Adobe Systems, Sun Microsystems, and others.[2] As a result of these submissions, a new W3C working group was created, which produced SVG.

code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,156
#7: Jun 5 '09

re: Embed an image in an .xls Excel sheet


Thanks Atli, I will check out this SVG.
But it would be no suprise to find that Microsoft has crippled this when used in .xls.
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,990
#8: Jun 5 '09

re: Embed an image in an .xls Excel sheet


Yea, your right. That wouldn't exactly come as a great shock :)

There is an alternative to that to, you know. Several, actually.
I like OpenOffice.org.
It can even handle a lot of the M$ Office formats.
Reply