I use below to output data to a excel file using PHP, -
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\">";
-
echo "<head>";
-
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\">";
-
echo "</head>";
-
echo "<body>";
-
however, I can't make it embed an image -
<img src="data:image/png;base64,'. $_POST['DATA_BIN'] .'">
-
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"
10 23913
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.
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.
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?
if Excel would support SVG, you could include that (because XHTML supports inline XML)
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
Thank you guys for all your suggestions. I think I will try Spreadsheet_Excel_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? -
<?php
-
require_once("Spreadsheet/Excel/Writer.php");
-
-
$workbook = new Spreadsheet_Excel_Writer();
-
$workbook->send("file.xls");
-
$worksheet =& $workbook->addWorksheet("worksheet");
-
$worksheet->setLandscape();
-
$worksheet->setFooter("footer");
-
$worksheet->centerHorizontally(1);
-
$worksheet->setMargins(0.5); // dalam inch
-
$worksheet->setPaper(9); // A4
-
$worksheet->hideGridLines();
-
$worksheet->setColumn(0, 0, 20);
-
$worksheet->setColumn(0, 1, 2);
-
$worksheet->setColumn(0, 2, 20);
-
-
$format1 =& $workbook->addFormat(array("Size" => 10, "Bold" => 1, "Align" => "center"));
-
$format1->setVAlign("vcenter");
-
$format2 =& $workbook->addFormat(array("Size" => 8, "Align" => "right"));
-
$format2->setVAlign("vcenter");
-
$format3 =& $workbook->addFormat(array("Size" => 8, "Align" => "left"));
-
$format3->setVAlign("vcenter");
-
-
$worksheet->write(1, 5, "write1", $format1);
-
$worksheet->write(2, 5, ("HAHA"), $format1);
-
$worksheet->write(3, 5, "Period : ", $format1);
-
$worksheet->write(5, 0, "mmm", $format3);
-
$workbook->close();
-
exit;
-
?>
-
thanks.
I found the reason it didn't show anything. The include_path in php.ini should be -
include_path = ".;C:\xampp\php\pear\;"
-
whereas mine was -
include_path = ".;C:\program files\xampp\php\pear\;"
-
Hope it saves somebody's time
Thank you for all your helps guys.
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!
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 :
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.
I must take a look at that PEAR class and find what it does exactly.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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:
...
|
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...
|
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...
|
by: Senthil |
last post by:
Hi all
I'm new in ajax. How to upload a image using ajax..
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
| |