我尝试时遇到问题。它只是加载php页面,但没有给我下载.doc
以下是我从第一页获取导出到MSWord请求的代码非常感谢!!
<a href="admweeklyprint.php">
<button class="btn btn-primary">Export to MsWord</button>
</a>
以下是我要导出的代码
<?php
include ('database_connection.php');
date_default_timezone_set('Asia/Manila');
$currentdate = date("y-m-d");
$currentTime = date("g:i:s a");
$sqldata ="SELECT *
from tbl_orders c, tbl_orderitems p WHERE dateordered > NOW() - INTERVAL 7 DAY AND c.orderID=p.orderID and paymentstatus='Complete' order by c.orderID ASC";
$getdata=mysql_query($sqldata);
?>
<html>
<head>
<link href="bootstrap/css/bootstrap.css" rel="stylesheet">
<link id="switch_style" href="bootstrap/css/united/bootstrap.css" rel="stylesheet">
<link href="css/main.css" rel="stylesheet">
<link href="css/jquery.rating.css" rel="stylesheet">
</head>
<body>
<center> <h1><img src="mvramPDF.PNG" alt="Logo" /> </h1>
<h2>Sale Report </h2>
</center>
<center>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Order ID</th>
<th>Product ID</th>
<th>Model</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
<th>Status</th>
<th>Date</th>
<th>Total Price with Tax</th>
</tr>
</thead>
<?php
$docname = "records_" . $currentdate . ".doc";
$x = 1;
$totalFinal=0;
$LastorderID=0;
while($data= mysql_fetch_array($getdata))
{
$orderID = $data["orderID"];
$totalprice = $data["totalprice"];
$status = $data["paymentstatus"];
$dordered = $data["dateordered"];
$prodID = $data["productID"];
$model = $data["model"];
$price = $data["price"];
$quantity = $data["quantity"];
$tax = $totalprice * .12;
$overall = $tax + $totalprice;
$total=$data['price']*$quantity;
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=$docname");
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
echo'<tr>
<tbody>
<td>'.(($LastorderID==$orderID) ? " " : $orderID).'</td>
<td>'.$prodID.'</td>
<td>'.$model.'</td>
<td>'.$quantity.'</td>
<td>₱'.$price.'</td>
<td>₱'.$total.'</td>
<td>'.(($LastorderID==$orderID) ? " " : $status).'</td>
<td>'.(($LastorderID==$orderID) ? " " : $dordered).'</td>
<td>'.(($LastorderID==$orderID) ? " " : "₱ $overall").'</td>
</tr>
';
if($LastorderID!=$orderID) $totalFinal+=$overall;
$LastorderID=$orderID;
$x++;
}
echo '
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td><strong>Total Sales: ₱'.$totalFinal.'</strong></td>
</tr>
</tbody>
</table>';
?>
</table>
</center>
</body>
</html>
非常感谢!!
答案 0 :(得分:0)
首先,你必须使用转换器将其转换为.doc,使用tcpdf或其他lib导出pdf更容易。
其次,如果要强制下载或显示文件,则必须在回显html <html>
的第一行之前发送标题()。