所以我無法從MySQL的數據導出到ExcelPHP在正確的格式不出口的MySQL數據庫
$output = '';
if(isset($_POST["export_excel"]))
{
$sql = "SELECT * FROM Logs ORDER BY item";
$result = mysqli_query($connect, $sql);
if(mysqli_num_rows($result) > 0)
{
$output .= '
<table class="table bordered="1">
<tr>
<th>Sort</th>
<th>Unit Size</th>
<th>Quantity</th>
<th>Price per Unit</th>
<th>Time</th>
</tr>
';
while($row = mysqli_fetch_array($result))
{
$output .= '
<tr>
<td>'.$row["Sort"].'</td>
<td>'.$row["Unit Size"].'</td>
<td>'.$row["Quantity"].'</td>
<td>'.$row["Price per Unit"].'</td>
<td>'.$row["Time"].'</td>
</tr>
';
}
$output .= '</table>';
header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=download.xls");
echo $output;
}
}
所以,當我打我的index.php頁面上的出口按鈕,它以這種格式輸出數據:Google Sheets Link to the excel file
<table class="table bordered="1">
<tr>
<th>Sort</th>
<th>Unit Size</th>
<th>Quantity</th>
<th>Price per Unit</th>
<th>Time</th>
</tr>
<tr>
<td></td>
<td>45</td>
<td>0</td>
<td>0</td>
<td>2016-08-11 16:53:12</td>
</tr>
<tr>
<td></td>
<td>6</td>
<td>0</td>
<td>0</td>
<td>2016-08-11 16:53:12</td>
</tr>
</table>
所以輸出正確的數據,但只是格式化是關閉的,這裏是什麼樣子的index.php頁面上: What the excel file should look like 做,如果任何人都可以告訴我,我做錯了那太棒了! 預先感謝您!
MS Excel可以打開html文件並將表格顯示爲excel電子表格,但這不是一個有效的xls文件,因此google-spreadsheets無法正確讀取它。 – Dekel
你會更好地寫入數據作爲CSV格式的數據而不是HTML – RamRaider