如何使列更宽,并且除了mysql中表的列名之外,标题不同?我如何让它有一个更大的字体?我是新手导出excel文件我不知道怎么做,我已经尝试过研究它但我也不理解它。提前谢谢你的帮助。
这是我的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 :(得分: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);