2013-09-16 80 views
0

我在嘗試時遇到問題。它只是加載的PHP頁面,但不給我一個.doc的下載將PHP頁面導出到.doc

這是我的代碼從第一頁獲取請求導出到MSWord非常感謝!

​​

而這裏的什麼我試圖出口

<?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) ? "&nbsp;" : $orderID).'</td> 
       <td>'.$prodID.'</td> 
       <td>'.$model.'</td> 
       <td>'.$quantity.'</td> 
       <td>&#8369;'.$price.'</td> 
       <td>&#8369;'.$total.'</td> 
       <td>'.(($LastorderID==$orderID) ? "&nbsp;" : $status).'</td> 
       <td>'.(($LastorderID==$orderID) ? "&nbsp;" : $dordered).'</td> 
       <td>'.(($LastorderID==$orderID) ? "&nbsp;" : "&#8369; $overall").'</td> 
       </tr>   
      ';  

     if($LastorderID!=$orderID) $totalFinal+=$overall; 



$LastorderID=$orderID; 
     $x++;  

    } 



echo '    
       <td>&nbsp;</td> 
       <td>&nbsp;</td> 
       <td>&nbsp;</td> 
       <td>&nbsp;</td> 
       <td>&nbsp;</td> 
       <td>&nbsp;</td> 
       <td>&nbsp;</td> 
       <td>&nbsp;</td> 
       <td><strong>Total Sales: &#8369;'.$totalFinal.'</strong></td> 
       </tr>   

</tbody> 
     </table>'; 


?> 

</table> 
</center> 
</body> 
</html> 

非常感謝你的代碼!

回答

0

首先,你必須用轉換器將它轉換成一個.doc文件,使用tcpdf或其他lib文件導出pdf更容易。

其次,如果您要強制下載或顯示文件,則必須在回顯html <html>的第一行之前發送標頭()。

http://www.php.net/manual/en/function.header.php

+0

謝謝主席先生反正我試圖用 blademaster

+0

但是當我回應它。格式化錯誤不是PDF或損壞。請提前幫我先生謝謝! – blademaster

+0

這是一個不同的問題,檢查你的路徑和環境路徑,看看http://stackoverflow.com/questions/8212040/display-pdf-on-website – dschniepp