哪位大哥哥大姐姐知道的话,能否给个实例啊
非常感谢!
<?
include("../common/db.inc.php");
include("../core/MySqlAccess_class.inc.php");
$sqlstr = str_replace("\\'","'",$_POST['sqlstr']);
$head_line = str_replace(",","\t",$_POST['head_line']) . "\n";
$filename = $_POST['filename'];
getExcel($sqlstr,$head_line,$filename);
function getExcel($sql, $head_line = "", $filename = "report") {
$table_value = $head_line;
$da = new DataAccess();
$da->ExecuteQurey($sql);
$num_fields = 0;
while ($row = $da->GetRow()) {
if (!$num_fields)
$num_fields = mysql_num_fields($da->result);
$i = 0;
foreach ($row as $field) {
if ($i) {
$table_value .= "\t" . $field;
}
else {
$table_value .= $field;
$i = 1;
}
}
$table_value .= "\n";
}
$da->FreeResult();
$da->ConnClose();
ob_start();
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=$filename.xls");
echo $table_value;
}
?>