使用PHP在Excel工作表中导入图像

时间:2014-05-27 08:55:39

标签: php excel import

尝试将图像插入Excel工作表。下面是我用于将数据导出到excel的代码。当我尝试插入图像时,它不插入图像,而只是显示图像的代码。任何帮助,将不胜感激。提前致谢

$ file_ending =“xls”;

//header info for browser
header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=$filename.xls");
header("Pragma: no-cache");
header("Expires: 0");

/*******Start of Formatting for Excel*******/
//define separator (defines columns in excel & tabs in word)
$sep = "\t"; //tabbed character

//start of printing column names as names of MySQL fields
echo("HR Motors\t\tREPAIR ORDER\t\t\t");
?> 
<img src="../images/Bosch-Logo.png" />
<?php
echo("\n");
echo("Repair Order\t".$result1['order_no']."\tLabour Bill No\t".$result1['labour_bill_no']."\t\t\n");
echo("Name\t".$custdata['customer_name']."\tRegd No\t".$custdata['registration_no']."\tDate\t".date('d/m/Y')."\n");
echo("Make\t".$custdata['make']."\tModel\t".$custdata['model']."\tContact No\t".$custdata['contact_no']."\n");
echo("Fuel Type\t".$custdata['fuel_type']."\tEmail\t".$custdata['email_id']."\tEngine No\t".$custdata['engine_no']."\n");
echo("Chassis No\t".$custdata['chassis_no']."\tODO Meter\t".$result1['odo_meter']."\t\t\n\n");
echo("Labour Bill\n");
echo("Service\tDescription\tPrice");
print("\n");
//end of printing column names

//start while loop to get data
while($row = mysql_fetch_row($result))
{
$schema_insert = "";
for($j=0; $j<mysql_num_fields($result);$j++)
{
if($j==0){
if(!isset($row[$j]))
$schema_insert .= "NULL".$sep;
elseif ($row[$j] != "")
$schema_insert .= "$row[$j]".$sep;
else
$schema_insert .= "".$sep;
}else{
if(!isset($row[$j]))
$schema_insert .= "NULL".$sep;
elseif ($row[$j] != "")
$schema_insert .= "$row[$j]".$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";
print(trim($schema_insert));
print "\n";
}

1 个答案:

答案 0 :(得分:0)

标签分隔值文件(您正在创建的文件)不是Excel文件,只是Excel可以读取的文件....但它只支持纯文本数据,没有格式,没有图像,没有特殊的Excel功能,如自动过滤甚至多个工作表。

如果要在Excel文件中嵌入图像,则需要使用PHPExcel

等库创建真正的OfficeOpenXML(.xlsx)或BIFF(.xls)格式的Excel文件