我有以下 html 文件:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr" lang="en">
<head>
</head>
<body>
<p align="center"><strong>Claims Search Results</strong></p>
<table id="ClaimsListPrint" class="printClaims">
<thead>
<tr style="background-color: rgb(241, 241, 241);">
<th style="background-color: rgb(215, 227, 235);">
Member
</th>
<th style="background-color: rgb(215, 227, 235);">
Date of Service
</th>
<th style="background-color: rgb(215, 227, 235);">
Provider
</th>
<th style="background-color: rgb(215, 227, 235);">
Claim Type
</th>
<th style="background-color: rgb(215, 227, 235);">
Status
</th>
<th style="background-color: rgb(215, 227, 235);">
Billed Amount
</th>
<th style="background-color: rgb(215, 227, 235);">
Paid by Plan
</th>
<th style="background-color: rgb(215, 227, 235);">
Member Responsiblity
</th>
</tr>
</thead>
<tbody>
<tr style="background-color: rgb(255, 255, 240);" class="claim">
<td class="claim-member">
John Sample
</td>
<td class="claim-dateOfService">
02/27/2011
</td>
<td class="claim-provider">
TestProv1
</td>
<td class="claim-claimType">
Medical
</td>
<td class="claim-status">
Processed
</td>
<td class="claim-billedAmount">
$145
</td>
<td class="claim-paidByPlan">
$125
</td>
<td class="claim-memberResponsibility">
$25
</td>
</tr>
<tr style="background-color: rgb(241, 241, 241);" class="claim">
<td class="claim-member">
John Sample
</td>
<td class="claim-dateOfService">
02/27/2011
</td>
<td class="claim-provider">
TestProv1
</td>
<td class="claim-claimType">
Medical
</td>
<td class="claim-status">
In-Process
</td>
<td class="claim-billedAmount">
-
</td>
<td class="claim-paidByPlan">
-
</td>
<td class="claim-memberResponsibility">
-
</td>
</tr>
</tbody>
</table>
</body>
</html>
我希望最终用户能够点击文件中的链接,如下所示:
<a id="link3" class="links" href="home.html">Export to Microsoft Excel</a>
当他们点击它时,我希望将表格导出为 csv 文件。我怎样才能做到这一点?我可以用 Javascript 或 PHP 或其他什么来做到这一点吗?
最佳答案
考虑使用 jQuery 插件:HTML Table to CSV
这是一条线:
$('#mytable').table2CSV();
您可以在这个 HTML Table To CSV demo 看到它的实际效果.
关于javascript - 如何创建可以将 html 导出到 CSV 文件的功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6191275/