0
我想導出html表格作爲excel。這個html表有一些隱藏的屬性,我想在導出表時刪除它們。所以我在下面嘗試。導出html表格作爲excel表格不包含隱藏元素
if ('undefined' !== typeof module) {
module.exports = function initExport() {
var data_type = 'data:application/vnd.ms-excel';;
$('table *:hidden').attr('data-todelete', 'true');
var clonedItem = $($('table').html());
$('table *:hidden').removeAttr('data-todelete');
clonedItem.find('*:hidden').remove();
var a = document.createElement('a');
a.href = data_type + ', ' + clonedItem.wrap("<div />").parent().html();
a.download = 'exported_table_' + Math.floor((Math.random() * 9999999) + 1000000) + '.xls';
a.click();
}
}
該excel是導出,但它包含以下內容。
<thead_ngcontent-scg-0=""></thead>
EDITED
我用
a.href = data_type + ', ' + clonedItem.html().replace(/ /g, '%20');
,而不是
a.href = data_type + ', ' + clonedItem.html();
然後下面的Excel cantains,這是我要導出HTML結構。
<thead _ngcontent-xbe-0="">
<tr _ngcontent-xbe-0="" role="row">
<th _ngcontent-xbe-0="" class="sorting_disabled" rowspan="1" colspan="1" style="width: 9px;">#</th>
<th _ngcontent-xbe-0="" class="sorting_disabled" rowspan="1" colspan="1" style="width: 63px;">Departure Airport</th>
<th _ngcontent-xbe-0="" class="sorting_disabled" rowspan="1" colspan="1" style="width: 72px;">Destination Airport</th>
<th _ngcontent-xbe-0="" class="sorting_disabled" rowspan="1" colspan="1" style="width: 56px;">Modified Time</th>
<th _ngcontent-xbe-0="" class="sorting_disabled" rowspan="1" colspan="1" style="width: 69px;">Availability</th>
<th _ngcontent-xbe-0="" class="sorting_disabled" rowspan="1" colspan="1" style="width: 54px;">Duration</th>
<th _ngcontent-xbe-0="" class="sorting_disabled" rowspan="1" colspan="1" style="width: 63px;">Departure Date</th>
<th _ngcontent-xbe-0="" class="sorting_disabled" rowspan="1" colspan="1" style="width: 24px;">Pax</th>
<th _ngcontent-xbe-0="" class="sorting_disabled" rowspan="1" colspan="1" style="width: 33px;">Total Price</th>
<th _ngcontent-xbe-0="" class="sorting_disabled" rowspan="1" colspan="1" style="width: 48px;">Time(Hours)</th>
<th _ngcontent-xbe-0="" class="sorting_disabled" rowspan="1" colspan="1" style="width: 47px;">Expired Time</th>
<th _ngcontent-xbe-0="" class="sorting_disabled" rowspan="1" colspan="1" style="width: 59px;">Last Possible Price Changed Time</th>
</tr>
</thead>
<tbody _ngcontent-xbe-0="">
<tr _ngcontent-xbe-0="">
<td _ngcontent-xbe-0="">1</td>
<td _ngcontent-xbe-0="">ASD</td>
<td _ngcontent-xbe-0="">ABC</td>
<td _ngcontent-xbe-0="">2017-06-05 12:34:44</td>
<td _ngcontent-xbe-0="" style="text-align: center;">true</td>
<td _ngcontent-xbe-0="" style="text-align: center;">13</td>
<td _ngcontent-xbe-0="">2017-07-31</td>
<td _ngcontent-xbe-0="">1_0_0</td>
<td _ngcontent-xbe-0="" style="text-align: right;">143.01</td>
<td _ngcontent-xbe-0="" style="text-align: right;">1.00</td>
<td _ngcontent-xbe-0="" style="text-align: center;">2017-06-05 13:34:44</td>
<td _ngcontent-xbe-0="" style="text-align: center;">2017-06-05 12:34:44</td>
</tr>
<!--data-->
</tbody>
任何建議表示讚賞。
謝謝
然後將Excel包含html代碼爲** # ... ** –
Rose18
你能告訴我你想要導出的表格的HTML結構嗎? – Zenoo
請檢查我編輯的問題 – Rose18