我使用jQuery
將HTML數據導出到Excel中。數據正在導出,但不會以正確的格式導出。在打開Excel文件時,它說:如何將HTML數據以正確的格式導出到Excel中?
「download.xls」的文件格式和後綴名不匹配。該文件可能已損壞或不安全。除非你信任它的來源,否則不要打開它。你還想打開嗎?
而當我打開它時,數據存在,但嚴重合並。我該怎麼辦?
echo "<div id=dvData3>";
//echo "<table border=5 cellpadding=5 cellspacing=0 style=border-collapse: collapse >";
echo "<table>";
echo "<tr>";
echo "<td width=14% align=center>Name</td>";
echo "<td width=14% align=center>Grand Total</td>";
echo "<td width=14% align=center>Expanse Type</td>";
echo "</tr>";
while($allrows=mysql_fetch_array($newresult1))
{
$name=$allrows["empid"];
$gamount=$allrows["gtotal"];
$exptype=$allrows["expanseType"];
echo "<tr>";
echo "<td width=14% align=center>$name</td>";
echo "<td width=14% align=center>$gamount</td>";
echo "<td width=14% align=center>$exptype</td>";
echo "</tr>";
}
echo "<tr>";
echo "<td width=14% align=center>Total Amount</td>";
echo "<td width=14% align=center>$Tamount</td>";
echo "</table>";
echo "</div>";
echo "<input type='button' id=\"btnExport3\" value=\" Export Table data into Excel \" />";
}
這是我的jQuery函數:
<script>
$(document).ready(function(){
$("#btnExport3").click(function (e) {
window.open('data:application/vnd.ms-excel,' + $('#dvData3').html());
//window.open('data:application/csv,charset=utf-8,' + $('#dvData').html());
e.preventDefault();
});
});
</script>
http://www.jwgoerlich.us/blogengine/post/2009/08/11/Excel-Extension-Hardening-and-Web-Applications.aspx –
.. 。和Excel中的表可能看起來不好,因爲它有不平衡的列數:最後一行只有2個單元格,而不是3.最後一行缺少結束 –
我已經添加 ..沒有任何改進。也錯誤類型是101786 – babar