2014-10-31 49 views
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"; 

?> 

回答

0

查看PHP代碼示例從這個鏈接,其中標題名稱是定製的,並且各行從數據庫中提取: http://www.easyxls.com/manual/basics/export-list-to-excel.html

爲了增加標題的字體大小使用此代碼:

 // Create an instance of the object used to format the cells 
    $xlsAutoFormat = new COM("EasyXLS.ExcelAutoFormat"); 

    //Set the style of the header 
    $xlsHeaderStyle = new COM("EasyXLS.ExcelStyle"); 
    $xlsHeaderStyle->setFontSize(18); 
    $xlsAutoFormat->setHeaderRowStyle($xlsHeaderStyle);