473,883 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to embed image(png) to Excel using php

6 New Member
I use below to output data to a excel file using PHP,
Expand|Select|Wrap|Line Numbers
  1. echo "<html xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\">";
  2.         echo "<head>";
  3.         echo "<meta http-equiv=Content-Type content=\"text/html; charset=us-ascii\"> <meta name=ProgId content=Excel.Sheet><meta name=Generator content=\"Microsoft Excel 11\">";
  4.         echo "</head>";
  5.         echo "<body>";
  6.  
however, I can't make it embed an image

Expand|Select|Wrap|Line Numbers
  1. <img src="data:image/png;base64,'. $_POST['DATA_BIN'] .'">
  2.  
It shows blank box with text : "the linked image cannot be displayed. the file may have been moved, renamed, or deleted. verify that the link points to the correct file and location"
Apr 12 '10 #1
10 24771
Dormilich
8,658 Recognized Expert Moderator Expert
the HTML img element does not contain image data. it holds a reference to the image, as you can clearly see in the error message.
Apr 12 '10 #2
NettSIte
7 New Member
Are you sure you are creating an Excel spreadsheet? Looks more like you are creating an HTML file similar to one created by Excel.

To create an Excell file, you need a whole different approach.

I often output a CSV file, which Excel can open, but I have never tried to include images. There is also a PEAR thing called something like Excel Spreadsheet Writer which is pretty powerful - it may be what you need.
Apr 13 '10 #3
bhbrayeun
6 New Member
Yes it does create an xls file, but as I said before, it cannot embed images from base64 encoded png files. I tried to use different approach : change the base64 encoded png file to a png file and save it in the server then I use <img> tag to display the images. But my problem now, when I delete the images from server, the image in the xls is also disappear because it's only a link I guess. Any suggestions?
Apr 13 '10 #4
Dormilich
8,658 Recognized Expert Moderator Expert
if Excel would support SVG, you could include that (because XHTML supports inline XML)
Apr 13 '10 #5
code green
1,726 Recognized Expert Top Contributor
Mind if I join in? I asked the same question last year http://bytes.com/topic/php/answers/8...ls-excel-sheet

Sorry I never did implement the suggestions.

NettSIte,
XLS is written in XHTML. It was possible to view the 'code behind' in Excel prior to Office 2007.
You can write simple HTML code as a string, write the string to a file, then save file as .xls and the file becomes a XLS spreadsheet with formatting, color etc.

But linking to CSS and images is only possible if full URL is supplied
Apr 13 '10 #6
bhbrayeun
6 New Member
Thank you guys for all your suggestions. I think I will try Spreadsheet_Exc el_Writer from pear because I really need the images to be embedded in my xls file. However, when I tried it, it showed blank page. Does it need some special configuration?

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require_once("Spreadsheet/Excel/Writer.php");
  3.  
  4.     $workbook = new Spreadsheet_Excel_Writer();
  5.     $workbook->send("file.xls");
  6.     $worksheet =& $workbook->addWorksheet("worksheet");
  7.     $worksheet->setLandscape();    
  8.     $worksheet->setFooter("footer");
  9.     $worksheet->centerHorizontally(1);
  10.     $worksheet->setMargins(0.5); // dalam inch
  11.     $worksheet->setPaper(9); // A4
  12.     $worksheet->hideGridLines();
  13.     $worksheet->setColumn(0, 0, 20);
  14.     $worksheet->setColumn(0, 1, 2);
  15.     $worksheet->setColumn(0, 2, 20);
  16.  
  17.     $format1 =& $workbook->addFormat(array("Size" => 10, "Bold" => 1, "Align" => "center"));
  18.     $format1->setVAlign("vcenter");
  19.     $format2 =& $workbook->addFormat(array("Size" => 8, "Align" => "right"));
  20.     $format2->setVAlign("vcenter");
  21.     $format3 =& $workbook->addFormat(array("Size" => 8, "Align" => "left"));
  22.     $format3->setVAlign("vcenter");
  23.  
  24.     $worksheet->write(1, 5, "write1", $format1);
  25.     $worksheet->write(2, 5, ("HAHA"), $format1);
  26.     $worksheet->write(3, 5, "Period : ", $format1);
  27.     $worksheet->write(5, 0, "mmm", $format3);
  28.     $workbook->close();
  29.     exit;
  30. ?>
  31.  
thanks.
Apr 13 '10 #7
bhbrayeun
6 New Member
I found the reason it didn't show anything. The include_path in php.ini should be
Expand|Select|Wrap|Line Numbers
  1. include_path = ".;C:\xampp\php\pear\;"
  2.  
whereas mine was
Expand|Select|Wrap|Line Numbers
  1. include_path = ".;C:\program files\xampp\php\pear\;"
  2.  
Hope it saves somebody's time

Thank you for all your helps guys.
Apr 13 '10 #8
code green
1,726 Recognized Expert Top Contributor
But the image is not actually 'embedded' in the XLS file, as is possible in a PDF file.
<src img is just linking to a live file. If this spreadsheet is sent as an attachment on an email or moved to another server this link is lost.
Unless a full www. address is given, firewalls permitting.

So maybe the image needs saving locally with the xls file, as when you save a web page.
Then whenever it is moved, one must ensure the pictures go with it!
Apr 13 '10 #9
bhbrayeun
6 New Member
I finally did it using pear. Using this library, the xls file is no longer an XML file, it's a binary file and I think it is embedded because I didn't use <img src...> anymore. Instead, I use :
Expand|Select|Wrap|Line Numbers
  1. $worksheet->insertBitmap
  2.  
However, the image files have to be a bmp format so we have to convert the format first. I use JPEXS' bmp library to convert formats.
Apr 13 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
82473
by: Pawel | last post by:
Hello All I tried to embed Excel sheet into HTML page by following command: <iframe src="Tmp.XLS" width="100%" height="500"></iframe> and it works, showing Excel sheet inside the page, but there is no way I can save the Excel sheet after it has been change. The Excel menu is not active and the system is not asking whether I want to save the changes or not.
1
2694
by: bborden | last post by:
Novice Access programmer here. I would like to display an image using the Toolbox Image object by calling the images file name using: =fPictureFiles(!!,1) in the Picture control. Below is the function which DOES actually returns a valid file
1
16248
by: Prasad More | last post by:
Hello, I am trying to write a text on Multi-page TIFF image using C# and .NET GDI+. I have written following code to do this. When I execute this code I get "Invalid Parameter User. at System.Drawing.Image.Save" error. public void addAnnotationStampOnImage() { string strStamp = Path.GetFileNameWithoutExtension(_ImageFileName); Size dSize; Image iMulti = Image.FromFile(_ImageFileName);
4
2139
by: Phil | last post by:
I've recently seen a couple of sites that have dynamically generated .png files on them and I'm wondering how to do it in c#, or if it's a server side thing. Here are a couple of links: http://www.serverspy.net/bin/hmon/12.183.157.40:27015/0/image.png http://miniprofile.xfire.com/gaspar.png Both of these images are real-time/dynamically generated, but they have a ..png extension. I understand how to create/manipulate and render images...
3
20088
by: Senthil | last post by:
Hi all I'm new in ajax. How to upload a image using ajax..
2
3345
by: Joe | last post by:
Hi I am able to embed Excel into a WebBrowser on my Dev machine but on a client machine an instance of Excel starts in it's own window outside of my form. I have used the WebBrowser with VS 2005 and the one with Office and get the same result. I have use the MS example from MSDN and get the same result on non-Dev machine I've posted this before and someone remarked it maybe due to IE setting? Does anyone know what the setting are and...
2
3789
by: user | last post by:
Hi all... i am trying to print an image using GDI - but the only thing i get is a black rectangle. Does anybody know what is wrong, or how else to get the bitmap on the printer (GDI+ is not possible. it is a POS printer (for restaurants) and the printer internal fonts are a MUST for printing speed. as far as i know printer internal fonts are only accessable through GDI, so all my printing is GDI up to now)
2
1526
by: wingsganesh | last post by:
Hi Guys, I dont know how to send image in windows mobile 6. i captured image using CameraCaptureDialog class and displayed that image in picture box. but still, i need to send this image in one specific link .... can anybody guide me..... how to send image...............
11
5844
by: shapper | last post by:
Hello, I am displaying an image on a few pages. The image size is 50 px height and 50 px width. In some pages I need the image to be 30x30 px in others 40x40 px and in others 50x50px. Can I scale the image using CSS? Thanks,
4
4911
by: neovantage | last post by:
Hey geeks, i want to draw a jpeg image of pattern chess. I can draw solid color image using gd libraray and here is my code //$t_im having image path, $t_wt,$t_ht is specified width and height respectively. $blue = imagecolorallocate($t_im,149,0,0); imagefilledrectangle($t_im,0,0,$t_wt,$t_ht,$blue);
0
9940
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11141
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10847
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10415
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9573
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7126
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5991
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3232
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.