gpt4 book ai didi

javascript - 如何在使用 jsPDF 时跳过某一列

转载 作者:行者123 更新时间:2023-12-03 07:35:51 26 4
gpt4 key购买 nike

我正在尝试使用 jsPDF 将 HTML 表导出为 PDF,但遇到重叠列问题。我必须跳过一些列,但不知道该怎么做。

这是我的表格:

<div class="wrapper wrapper-content">
<div class="row">
<div class="col-lg-12">
<div class="ibox float-e-margins">
<a class="btn btn-primary btn-xs pull-right m-r-xs" ng-click="toPDF()">PDF çıktısı al</a>
<a class="btn btn-primary btn-xs pull-right m-r-xs" ng-click="toExcel()">Excel çıktısı al</a>
<div class="ibox-content" id="table">
<table id="archiveTable" class="table table-responsive table-hover">
<thead>
<tr>
<th id="bypassme" class="text-center noExl">Şüpheli</th>
<th width="20">No</th>
<th>Plaka</th>
<th>Ad</th>
<th>Plaka Noktası</th>
<th>Sahip Türü</th>
<th>Tarih</th>
</tr>
</thead>
<tbody>
<tr class="clickable" ng-repeat="data in archivedata" ng-click="showArchiveDetails(data)">
<td ng-class="{'text-danger': data.dangerous}" class="text-center noExl">
<span ng-if="data.dangerous" tooltip="Şüpheli"><i class="fa fa-exclamation-circle"></i></span>
</td>
<td>{{(shownCurrentPage-1)*resultsPerPage + $index + 1}}</td>
<td>{{data.plate}}</td>
<td>{{people[data.ownerType][data.ownerId].name}}</td>
<td>{{data.platePoints.pointName}}</td>
<td ng-switch="data.ownerType">
<span ng-switch-when="1">{{labels.resident}}</span>
<strong ng-switch-when="2">{{labels.guest}}</strong>
<span ng-switch-when="3">Tanınmayan</span>
<span ng-switch-when="4">Düzenli Ziyaretçi</span>
</td>
<td>{{data.lprDate | date:'dd/MM/yyyy HH:mm'}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>

这是 Javascript 代码:

$scope.toPDF = function(){
var from = $filter('date')($scope.archive.from,'dd.MM.yyyy HH.mm');
var to = $filter('date')($scope.archive.to,'dd.MM.yyyy HH.mm');
var filename = "Arşiv - " + from + " - " + to + ".pdf";

var pdf = new jsPDF('p', 'pt', 'letter');
// source can be HTML-formatted string, or a reference
// to an actual DOM element from which the text will be scraped.
source = $('#table')[0];

// we support special element handlers. Register them with jQuery-style
// ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
// There is no support for any other type of selectors
// (class, of compound) at this time.
specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#bypassme': function (element, renderer) {
// true = "handled elsewhere, bypass text extraction"
return true
}
};
margins = {
top: 80,
bottom: 60,
left: 40,
width: 522
};
// all coords and widths are in jsPDF instance's declared units
// 'inches' in this case
pdf.fromHTML(
source, // HTML string or DOM elem ref.
margins.left, // x coord
margins.top, { // y coord
'width': margins.width, // max width of content on PDF
'elementHandlers': specialElementHandlers
},

function (dispose) {
// dispose: object with X, Y of the last line add to the PDF
// this allow the insertion of new lines after html
pdf.save(filename);
}, margins);
};

我希望在导出时跳过名为“Şüpheli”的列,因为没有可供打印的文本。

尽管对于此表,最好在该列中放置适当的文本而不是图标,但我仍然需要对其他表中的某些列使用此忽略功能。

这是我现在得到的: enter image description here

谢谢。

最佳答案

在将源变量传递给 fromHTML 之前,您可以编辑源变量中传递的内容。可以根据类名删除部分。

例如:

cln_source2 = source.cloneNode(true);
var deleterows = [];
$(cln_source2.childNodes[1].rows).each(function(ri, row){
var deletecells = [];
$(row.cells).each(function(ci, cell){
if( $(cell).hasClass('no_export') )
deletecells.push(ci);
});
$.each(deletecells.reverse(), function(i, ii){
row.deleteCell(ii);
});
if($(row).hasClass('omitted-row'))
deleterows.push(ri);

});
$.each(deleterows.reverse(), function(i, ii){
cln_source2.childNodes[1].deleteRow(ii);
});

这将删除类名为“no_export”的任何项目,甚至使用“omissed-row”删除整行。

这是一个 fiddle ,显示正在导出的表,并忽略最后一列:fiddle

关于javascript - 如何在使用 jsPDF 时跳过某一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35617430/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com