473,473 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How do you embed images into Excel through PHP

2 New Member
Right now I'm making a little test page to see how well I could export data from a MySQL database into an Excel spreadsheet. This is a dynamically created .xls and there could be almost no rows or even thousands of rows created, it all depends on what the person wants to get.

I have outputting basic data well. Right now it gets up to ~65k rows of output. What I need now is to be able to embed images into these Excel files. I've been searching since yesterday morning and have yet to find anything all that useful.

Here is the code:
(A part of the top has been omitted, it's just the database information)
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     $filename = 'Dump_For_Table_'. $tblname;
  3.     $title = '';
  4.  
  5.     $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
  6.     $sql = 'SELECT * FROM ' . $tblname;
  7.     $result = mysqli_query($mysqli, $sql);
  8.  
  9.     header('Content-Type: application/vnd.ms-excel');
  10.     header('Content-Disposition: attachment; filename='. $filename .'.xls');
  11.     header('Pragma: no-cache');
  12.     header('Expires: 0');
  13.  
  14.     echo($title."\n");
  15.  
  16.     $sep = "\t";
  17.  
  18.     //column names
  19.     while($row = mysqli_fetch_field($result))
  20.     {
  21.         echo $row->name . $sep;
  22.     }
  23.  
  24.     echo("\n");
  25.     //end column names
  26.  
  27.     while($row = mysqli_fetch_array($result))
  28.     {
  29.         //set_time_limit(60); // HaRa
  30.         $schema_insert = "";
  31.         for($i=0; $i<mysqli_num_fields($result);$i++)
  32.         {
  33.             if(!isset($row[$i]))
  34.                     $schema_insert .= " ".$sep;
  35.             elseif ($row[$i] != "")
  36.                     $schema_insert .= "$row[$i]".$sep;
  37.             else
  38.                     $schema_insert .= "".$sep;
  39.         }
  40.         $schema_insert = str_replace($sep."$", "", $schema_insert);
  41.         $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
  42.         $schema_insert .= "\t";
  43.         echo(trim($schema_insert));
  44.         echo "\n";
  45.     }
  46. ?>
  47.  
I know that there is PHPExcel and PEAR but I'd rather not have to install those just to be able to insert images. PHPExcel I know isn't able to handle the largest amount of rows we might have, another programmer before me tried it and it didn't work. I tried looking at some of the code for PHPExcel but I can't follow it well enough to see what code they're actually sending to Excel to make it accept images. I don't know about PEAR though.
Dec 16 '10 #1
2 3289
johny10151981
1,059 Top Contributor
What software are you using then? I need to know that too.

I worked with PHPExcell a little it can handle image very well you can follow example14. its a small file.

And I am not sure about 65K rows. but are you sure that Excel itself can handle this amount data. If so then you should try to increase your memory limit using php.ini file
Dec 17 '10 #2
Francis Bolap
2 New Member
I'm just using the code above. I'm not using any extra software or libraries from anywhere else.

Although after searching through the files I learned that PHPExcel makes an xml file that Excel can read. Mind you I'm fairly certain that that's what it does. It was a little hard to follow it all. I'm going to try just making an xml file and see what happens.

Excel has a maximum amount of rows that's somewhere around 65k. I got it to output that many from a table I have but no more, which is fine.

Edit: I'm caving. I'm just going to try and use PEAR. If I manage to get images to go into Excel images properly using PEAR I'll edit my post with the information here in case anyone else asks.
Dec 17 '10 #3

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

Similar topics

0
by: Stan Brown | last post by:
URL: http://www.acad.sunytccc.edu/instruct/sbrown/stat/mygrades.htm As I read the spec, I need _either_ data= and type= _or_ classid= and codetype=. I've tried it both ways and neither works. I...
1
by: ComStar | last post by:
I have a vb.net program that sends out html emails via smtp on a windows 2003 server. Question I have is how do you embed images in an html email message? You get to define the body but how do...
2
by: Julia | last post by:
Hi, When generating CHM from my assemblies and XML documentation is it possible to embed images? Thanks.
3
by: Boris Condarco | last post by:
Hi gurus, I'm using excel 2000 to show data that comes from datagrid. The problem is that for any reason the asp.net application maintains the excel open, even though, i do close it. Besides,...
4
by: zhangyl | last post by:
I want to embed the excel worksheet into my application and use it like datagrid, if somebody can tell a solution, whether visual studio 2005 can do it ? thanks.
13
by: Lloyd Dupont | last post by:
In the good old days I believe people were using the arcane technology which came to be known as COM+ to embed other application's document in their own document. Like a Word with document a...
0
by: =?Utf-8?B?Tml5YXpp?= | last post by:
Hi all, Does anyone know how to embed the Excel file in VB.NET 2005 Resources? Here is what I am doing at the moment: 1) In my VB.NET 2005 project code I load the excel with it path into...
11
by: sandeepkedlaya | last post by:
Hello, I need to copy images from a folder and copy to a word document. I have done as follows.. but It copies only last image. Can any one of you help me in this.. Private Sub Page_Load(ByVal...
9
by: AGP | last post by:
I have a VB6 application that has an OLE container with an embedded Excel chart. Our office updated to Excel 2007 and now although the app works the charts looks like crap. Since the app is fairly...
1
by: Kingsway | last post by:
How do i upload JPEG images to Oracle. Not possible to EMBED images into spreadsheet. I know SQL Laoder can do the job but not suree how to EMBED JPEG images to Excel or TXT file.
0
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,...
0
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...
0
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,...
1
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...
0
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...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.