使用PHP将HTML表格下载到excel中

时间:2015-12-08 00:04:09

标签: php html excel

我的网页上有一个表格,其中包含基于人员呼号的数据。一旦数据在表格中,我就有了一个下载按钮,可以将表格下载到Excel文档中。现在当你点击它下载的按钮和excel文件,但我的表不在那里。如何用我的表填充excel文件?任何想法或想法都非常感谢!

<?php foreach ( $station_array as $station ) {
            $name = $station[ 'name' ];
            $temp = $station[ 'temp' ];
            $time = $station['time'];   
            $temp1 = ( ( 9 / 5 ) * $temp ) + 32;        
            echo '<table border = "1"  name = "table" class = "Choices">    
            <tr>
                <th>NO.</th>
                <th>Fields</th>
                <th>Data</th>
            </tr>
                <tr><td>1</td>
                <td>Callsign</td>
                <td>'.$name.'</td>                  
                </tr>
                <tr>
                    <td>2</td>
                    <td>Time</td>
                    <td>'.$time.'</td>
                </tr>
                <tr>
                <td>3</td>
                <td>Temperature</td>
                <td>'.$temp1.'</td>
               </tr></tabe>';?> 

<form class = "downLoadButton" action ="downLoad.php" method="post"> <input type="submit" name = "submit" value="Download Data" /> </form>

的download.php

<?php
  $filename = "aprsData_" . date('Ymd') . ".xls";
  header("Content-Disposition: attachment; filename=\"$filename\"");
  header("Content-Type: application/vnd.ms-excel");

  if (isset($_POST["submit"])) {
    $data .= $_POST["table"];
    }

 $flag = false;
  foreach($data as $row) {
    if(!$flag) {
      // display field/column names as first row
      echo implode("\t", array_keys($row)) . "\n";
      $flag = true;
    }
    echo implode("\t", array_values($row)) . "\n";
  }
?>`

0 个答案:

没有答案