簡體   English   中英

如何通過使用php或js提供相應的按鈕將html表導出為ex​​cel或pdf

[英]how to export a html table into excel or pdf by giving the respective buttons using php or js

我創建了一個表,其中將有員工的請假詳細信息,並應用了迄今為止對請假詳細信息的排序。 它將以表格格式顯示我。 現在,我想添加“導出到Excel”和“導出到pdf”之類的按鈕,以便我可以從那里以excel或pdf格式下載表格。

下面是代碼

<form name="filter" method="POST">

                            <input type="date" name="start">
                            <input type="date" name="end">
                            <input type="submit" name="submit" value="Filter">
                            </form>

   <table id="example" class="display" style="width:100%">
<tbody>
<?php
  if(isset($_POST['submit'])){
    $Status=1;
    $end = $_POST['end'];
    $start = $_POST['start'];
    $sql = "SELECT * FROM tblleaves 
       WHERE Status='".$Status."' AND (start BETWEEN '".$start."' AND '".$end."' OR end BETWEEN '".$start."' AND '".$end."' + INTERVAL 1 DAY )" ; 
   $result = mysqli_query($conn,$sql)or die(mysqli_error($conn));

     echo "<table>";
     echo "<thead>
                                    <tr>

                                         <th>title</th>
                                         <th>empid</th>
                                         <th>Team</th>
                                         <th>Leave Type</th>
                                        <th>Start Date</th>
                                        <th>End Date</th>
                                         <th>Description</th>

                                    </tr>
                                </thead>";

  while($row = mysqli_fetch_array($result)) {
$id = $row['id'];
$LeaveType = $row['LeaveType'];
$end = $row['end'];
$start=$row['start'];
$Description=$row['Description'];

$Status=$row['Status'];
$empid=$row['empid'];
$team=$row['team'];
$title=$row['title'];
echo "<td style='width: 200px;'>".$title."</td><td>".$empid."</td><td>".$team."</td><td style='width: 100px;'>".$LeaveType."</td><td>".$start."</td><td>".$end."</td><td>".$Description."</td></tr>";
      } 

    echo "</table>";

}
  else{

require('../includes/config.php');

$sql = "SELECT * FROM tblleaves where Status=1 order by id desc";

$result = mysqli_query($conn,$sql)or die(mysqli_error());

 echo "<table>";
 echo "<thead>
                                    <tr>

                                        <th>title</th>
                                         <th>empid</th>
                                         <th>Team</th>
                                        <th>Leave Type</th>
                                        <th>Start Date</th>
                                        <th>End Date</th>
                                         <th>Description</th>


                                    </tr>
                                </thead>";

  while($row = mysqli_fetch_array($result)) {
$id = $row['id'];
$LeaveType = $row['LeaveType'];
$end = $row['end'];
$start=$row['start'];
$Description=$row['Description'];

$Status=$row['Status'];
$empid=$row['empid'];
$team=$row['team'];
$title=$row['title'];
echo "<td style='width: 200px;'>".$title."</td><td>".$empid."</td><td>".$team."</td><td style='width: 100px;'>".$LeaveType."</td><td>".$start."</td><td>".$end."</td><td>".$Description."</td></tr>";
} 

  echo "</table>";
  mysqli_close($conn);

    }
 ?>                     </tbody>
                            </table>

要將html表導出為pdf,可以使用dompdf庫。

有多個PDF庫可用於將表轉換為pdf,例如DOMPDF,FPDF等。您還可以找到將表轉換為.xls的庫。

請檢查一次。 也許您會發現這很有用。 如何將html表導出為xlsx文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM