我想用word或excel导出这种报告格式请帮帮我。使用此代码,我现在从数据库中获取正确的数据,我想将其导出。
<form name="form1" method="post" action="daily.php">
<h1 style="padding-left:150px;"> Daily Report </h1>
<div class="report" style="overflow:auto;height:400px;">
<?php $q="select cid,gtotal from db_transaction where tdate='$dat'";
$a=mysql_query($q);
echo '<table border="1" class="curvedEdges">';
echo '<th width="30">Sr </th><th> Customer Name </th> <th>Services </th> <th>Service By </th> <th> Amount</th>';
$i=1;$gd=0;
while($row=mysql_fetch_array($a))
{
$qa=mysql_query("select cname from db_customers where cid=$row[0]");
$cnm=mysql_fetch_array($qa);
$sd=mysql_query("select service,price from db_sale_service where cid=$row[0]");
echo '<tr><td>'.$i.'</td><td>'.strtoupper($cnm[0]).'</td><td><table><th>Name</th><th>Price</th>';
while($snm=mysql_fetch_array($sd))
{
echo '<tr><td>'.$snm[0].'</td> <td>'.$snm[1].'</td></tr>';
}
$sd=mysql_query("select serviceby from db_sale_service where cid=$row[0]");
$snm=mysql_fetch_array($sd);
echo '</table></td><td>'.$snm[0].'</td><td>'.$row[1].'</td></tr>';
$i++; $gd+=$row[1];
}
echo '<tr><td colspan="3" align="center"><strong>Tolday\'s Total </strong></td><td colspan="2" align="center"><strong>'.$gd.'</strong></td></tr>';
echo '</table>';
?> </div>
</form>
答案 0 :(得分:0)
使用此特定代码段并根据您的要求进行修改。
<?PHP
// Original PHP code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.
function cleanData(&$str)
{
$str = preg_replace("/\t/", "\\t", $str);
$str = preg_replace("/\r?\n/", "\\n", $str);
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
}
// filename for download
$filename = "website_data_" . date('Ymd') . ".xls";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel");
$flag = false;
$result = pg_query("SELECT * FROM table ORDER BY field") or die('Query failed!');
while(false !== ($row = pg_fetch_assoc($result))) {
if(!$flag) {
// display field/column names as first row
echo implode("\t", array_keys($row)) . "\r\n";
$flag = true;
}
array_walk($row, 'cleanData');
echo implode("\t", array_values($row)) . "\r\n";
}
exit;
?>
更多http://www.the-art-of-web.com/php/dataexport/#.UbB-PECLA6I