javascript - Angularjs将数据表下载到csv
问题描述
有人可以教我如何将数据表从 json 转换为 PDF 吗?我只能找到大量没有解释的代码。如果有人知道正确解释的地方并与我分享,那就太酷了。赞赏!
我的数据表示例:
<table class="table table-striped table-hover">
<thead>
<tr>
<th ng-click="sort('id')">Name
<span class="glyphicon sort-icon" ng-show="sortKey=='id'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
</th>
<th ng-click="sort('first_name')">Block No.
<span class="glyphicon sort-icon" ng-show="sortKey=='first_name'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
</th>
<th ng-click="sort('last_name')">Postal Code
<span class="glyphicon sort-icon" ng-show="sortKey=='last_name'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
</th>
<th ng-click="sort('hobby')">Street Name
<span class="glyphicon sort-icon" ng-show="sortKey=='hobby'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
</th>
</tr>
</thead>
<tbody>
<tr dir-paginate="audit in auditoriums|orderBy:sortKey:reverse|filter:search|itemsPerPage:5 | limitTo: 1 - auditoriums.length">
<td>{{audit.NAME}}</td>
<td>{{audit.ADDRESSBLOCKHOUSENUMBER}}</td>
<td>{{audit.ADDRESSPOSTALCODE}}</td>
<td>{{audit.ADDRESSSTREETNAME}}</td>
</tr>
</tbody>
</table>
解决方案
您可以尝试使用此客户端 JavaScript PDF 生成
var doc = new jsPDF()
doc.text('Sample text', 11100221, 22,44)
doc.save('sampleText.pdf')