我的网站中有一个数据表,我想执行某些操作,例如导出 csv、excel、打印等,但表中的某些值显示为图标,从而使数据表无法导出这些值。
这里有一个例子
<table>
<tr>
<td>Name: Sammy</td>
<td>email: [email protected]</td>
<td><a href="https://instagram.com/sammy"><i class="fas fa-instagram"></i></a></td>
<tr>
</table>
所以现在当我尝试导出时,我希望 Instagram 链接也导出。但数据表没有捕获这一点。我怎样才能做到这一点?
默认导出仅支持两种不同的格式,即Numbers和InlineString
要解决此问题有很多方法和替代方案,您可以尝试以下任何一种:
customize
选项调整导出这里尝试使用此代码获取
customize
选项,
customize: function(xlsx) {
var sheet = xlsx.xl.worksheets['sheet1.xml'];
// Loop over all cells in sheet
$('row c', sheet).each( function () {
// if cell starts with http
if ($('is t', this).text().indexOf("http") === 0) {
// (2.) change the type to `str` which is a formula
$(this).attr('t', 'str');
//append the formula
$(this).append('<f>' + 'HYPERLINK("'+$('is t', this).text()+'","'+$('is t', this).text()+'")'+ '</f>');
//remove the inlineStr
$('is', this).remove();
// (3.) underline
$(this).attr( 's', '4' );
}
});
}
您可以尝试使用
热键使用
HYPERLINK
公式
如果这些选项都不起作用,那么您还可以尝试使用 DataTables 论坛的 PHPExcel 参考 作为导出选项,这是 stackOverflow answer
希望这有帮助...