2017-12-06 8 views
0

私はPHPで新しく、SQLサーバからの情報を持つテーブルを表示するWEBアプリケーションを開発しています。データベース、EXCELファイルを生成するボタンを追加したいという問題表示されているテーブルが含まれていますか?それは可能ですか? @Ranjitこれは表が表示され、ExcelはあなたがExcelシートに挿入し、その後、データを手動で選択する必要があります、PHPのライブラリがありますPHPを使用してExcelファイルを生成する

編集1

<?php 
$ch=""; 
if(isset($_POST['historique'])) 
{ 
    if ((!empty($_POST['Date_de_debut']))&& (!empty($_POST['Date_de_fin']))&&(!empty($_POST['Heure_de_debut']))&&(!empty($_POST['Heure_de_fin']))) 
    { 
       $ch= "(CONVERT(Datetime, '".$_POST['Date_de_debut']." ".$_POST['Heure_de_debut'].".000',120)) and (CONVERT(Datetime, '".$_POST['Date_de_fin']." ".$_POST['Heure_de_fin'].".000',120))"; 
     ?> 
<table id="tab" border="1"> 
       <tr> 
       <th><font color="red">Date</font></th> 
       <th><font color="red">Agent</font></th> 
      <th><font color="red">numéro</font></th>  
       </tr> 
<?php 

$search = " // my query 
where operationDate between" .$ch; 
$stmt = mssql_query($search); 
          while ($data = mssql_fetch_assoc($stmt)) 
          { 
            ?> 
    <tr> 
<td><?php echo utf8_encode ($data['operationDate']);?></td> 
<td><?php echo utf8_encode ($data['fullName']);?></td> 
<td><?php echo utf8_encode ($data['number']);?></td> 
            </tr> 
<?php 
    } } 

    ?> 
     </table> 
<?php 
} 
$output =''; 
if(isset($_POST['excel'])) 
{ 
    if ((!empty($_POST['Date_de_debut']))&& (!empty($_POST['Date_de_fin']))&&(!empty($_POST['Heure_de_debut']))&&(!empty($_POST['Heure_de_fin']))) 
    { 
    $rq = "// my query 
           where operationDate between" ."(CONVERT(Datetime, '".$_POST['Date_de_debut']." ".$_POST['Heure_de_debut'].".000',120)) and (CONVERT(Datetime, '".$_POST['Date_de_fin']." ".$_POST['Heure_de_fin'].".000',120))"; 
    $res = mssql_query($rq); 
    if(mssql_num_rows($res)>0) 
    { 
    $output.='<table border=1> 
      <tr> 
        <th>Date</th> 
        <th>Depanneur</th> 
        <th>numéro</th> 
       </tr> 
       '; 
       while ($row=mssql_fetch_array($res)) 
       { 
       $output .=' 
       <tr> 
        <td>'.$row["operationDate"].'</td> 
        <td>'.$row["fullName"].'</td> 
        <td>'.$row["number"].'</td> 
       </tr>'; 
       } 
          $output .='</table>'; 
       header("Content-Type: application/xls;charset=UTF-8"); 
       header("Content-Disposition: attachement; filename=file.xls"); 

       echo $output; 
          //mssql_close($conn); 
}}} 
?> 

答えて

-1
+0

情報がそうであるように私はすでにデータベースに接続されている - ソース

//define separator (defines columns in excel & tabs in word) $sep = "\t"; //tabbed character $fp = fopen('database.xls', "w"); $schema_insert = ""; $schema_insert_rows = ""; //start of printing column names as names of MySQL fields 

2)エクセル

のファイル名を定義します:あなたは)この

1に従ってデータベースに接続することができます画面に表示される "show"ボタンをクリックすると、エクセルファイルの情報をエクスポートするために再接続する必要がありますか? 2回目のクエリを実行し、情報を1回以上フェッチしてエクセルファイルに保存する必要がありますか?または最初のクエリで直接渡す必要がありますか? PS:MICROSOFT SQL Serverを使用しています – Brainiac

+0

あなたは何を試してみることができますか? – Ranjit

+0

私はExcelファイルを生成しましたが、問題はファイルがテーブルのみを生成しないことです。穴のHTMLページとボタンテキストも生成します。 – Brainiac

関連する問題