0
如何讓列更寬,並且標頭不同於mysql中表的列名?以及如何讓它具有更大的字體?我是新出口的Excel文件,我不知道該怎麼做,我試過研究它,但我也不明白。預先感謝您的幫助。使用PHP設計導出XLS
這裏是我的export.php
<?php
require 'config.php';
$SQL = "SELECT prod_brand, prod_name, prod_category, prod_price, prod_desc, prod_quantity from inventory";
$header = '';
$result ='';
$exportData = mysql_query ($SQL) or die ("Sql error : " . mysql_error());
$fields = mysql_num_fields ($exportData);
for ($i = 0; $i < $fields; $i++)
{
$header .= mysql_field_name($exportData , $i) . "\t";
}
while($row = mysql_fetch_row($exportData))
{
$line = '';
foreach($row as $value)
{
if ((!isset($value)) || ($value == ""))
{
$value = "\t";
}
else
{
$value = str_replace('"' , '""' , $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$result .= trim($line) . "\n";
}
$result = str_replace("\r" , "" , $result);
if ($result == "")
{
$result = "\nNo Record(s) Found!\n";
}
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename=InventoryExport'.date('m-d-Y H:i:s').'.xls');
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$result";
?>