我有一个导出到Excel函数,该函数在我的本地主机上运行良好。但是,一旦将其发布到IIS 10,它就会从我要查找的“正文”中返回数据。 这是我的桌子:
<div class="pull-right">
<a onclick="exportExcel()" href=""><i class="fas fa-file-excel"></i> Export to Excel</a>
<a onclick="printDiv('printableArea')" title="Print" href=""><i class="fas fa-print"></i> Print</a>
</div>
<div class="col-md-12 accordions" id="printableArea">
<table class="small-table instant-table" id="results">
<thead>
<tr class="blue-heading">
<th class="sorttable_alpha">
Date
</th>
<th class="sorttable_alpha">
Numbers
</th>
</tr>
</thead>
@foreach (var item in Model.OrderByDescending(x => x.Date))
{
<tbody>
<tr data-toggle="collapse" data-target="#numbers@(item.Id)" class="clickable">
<td data-th="Date">
<strong>@item.Date</strong>
</td>
<td>
@item.Numbers
</td>
</tr>
</tbody>
<tbody class="no-print exclude no-Excel">
<tr>
<td colspan="5" style="padding:0 !important" class="no-print">
<div id="numbers@(item.Id)" class="collapse">
<table class="small-table table-bordered">
<thead>
<tr>
<th>Count</th>
<th>Total</th>
</tr>
</thead>
<tr>
<td data-th="Count">@ViewBag.Count</td>
<td data-th="Total">@ViewBag.Total</td>
</tr>
</table>
</div>
</td>
</tr>
</tbody>
}
</table>
</div>
如您所见,我有2个“正文”部分,一个显示日期和数字,另一个显示计数和总计。导出到Excel时,我想隐藏第二个,并使用此JS函数:
function exportExcel() {
//This will remove the div that contains the Count and Total
$('tbody').each(function () {
$('.no-Excel').remove();
});
var a = document.createElement('a');
//Getting data from our div that contains the HTML table
var data_type = 'data:application/vnd.ms-excel';
var table_div = document.getElementById('printableArea');
var table_html = table_div.outerHTML.replace(/ /g, '%20');
a.href = data_type + ', ' + table_html;
//Setting the file name
a.download = 'Results.xls';
//Triggering the function
a.click();
//Just in case, prevent default behaviour
e.preventDefault();
}
再一次,它在我的本地计算机上运行良好,并使用IIS中的标头导出到Excel,但是它不显示我要显示的tbody的内容。在浏览器上调试时,它们在两种环境中传递的数据完全相同。
有什么办法可以解决吗? 谢谢!