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)
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.
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)
Code:
<?php
$filename = 'Dump_For_Table_'. $tblname;
$title = '';
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
$sql = 'SELECT * FROM ' . $tblname;
$result = mysqli_query($mysqli, $sql);
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename='. $filename .'.xls');
header('Pragma: no-cache');
header('Expires: 0');
echo($title."\n");
$sep = "\t";
//column names
while($row = mysqli_fetch_field($result))
{
echo $row->name . $sep;
}
echo("\n");
//end column names
while($row = mysqli_fetch_array($result))
{
//set_time_limit(60); // HaRa
$schema_insert = "";
for($i=0; $i<mysqli_num_fields($result);$i++)
{
if(!isset($row[$i]))
$schema_insert .= " ".$sep;
elseif ($row[$i] != "")
$schema_insert .= "$row[$i]".$sep;
else
$schema_insert .= "".$sep;
}
$schema_insert = str_replace($sep."$", "", $schema_insert);
$schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
$schema_insert .= "\t";
echo(trim($schema_insert));
echo "\n";
}
?>
Comment