<?
// Author: Linmic, email: linmicya@gmail.com
$host = ""; // your db host (ip/dn)
$user = ""; // your db’s privileged user account
$password = ""; // and it’s password
$db_name = ""; // db name
$tbl_name = ""; // table name of the selected db
$user = ""; // your db’s privileged user account
$password = ""; // and it’s password
$db_name = ""; // db name
$tbl_name = ""; // table name of the selected db
$link = mysql_connect ($host, $user, $password) or die(‘Could not connect: ‘ . mysql_error());
mysql_select_db($db_name) or die(‘Could not select database’);
mysql_select_db($db_name) or die(‘Could not select database’);
$select = "SELECT * FROM `".$tbl_name."`";
$col_title = ‘<tr>’.$col_title.‘</tr>’;
while($row = mysql_fetch_row($export)) {
$line = ”;
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace(‘"’, ”, $value);
$value = ‘<td>’ . $value . ‘</td>’ . "\t";
}
$line .= $value;
}
$data .= trim("<tr>".$line."</tr>")."\n";
}
$line = ”;
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace(‘"’, ”, $value);
$value = ‘<td>’ . $value . ‘</td>’ . "\t";
}
$line .= $value;
}
$data .= trim("<tr>".$line."</tr>")."\n";
}
header("Content-Type: application/vnd.ms-excel;");
header("Content-Disposition: attachment; filename=export.xls");
header("Pragma: no-cache");
header("Expires: 0");
header("Content-Disposition: attachment; filename=export.xls");
header("Pragma: no-cache");
header("Expires: 0");
$xls_header = ‘<html xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=utf-8" />
</head>
<body>
<table border="1" align="center">’;
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=utf-8" />
</head>
<body>
<table border="1" align="center">’;
$xls_footer = ‘</table>
</body>
</html>’;
</body>
</html>’;
?>
沒有留言:
張貼留言