导出到Excel时删除HTML标记 [英] HTML tag removing when export to excel
本文介绍了导出到Excel时删除HTML标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此脚本将html表导出到excel文件,但是我在表中有图像标签,因此我想在脚本导出到excel时删除该标签.这是我正在使用的脚本
I am using this script to export html table to excel file but I have image tag in table so I want to remove that tag when script export to excel. Here is the script I am using
<script type="text/javascript">
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,'
, template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
, base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
, format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }
return function(table, name) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
window.location.href = uri + base64(format(template, ctx))
}
})()
</script>
<input type="button" onclick="tableToExcel('datatable', 'W3C Example Table')" value="Export to Excel">
推荐答案
您可以删除< img>
标签,如下所示:
You can remove <img>
tags like this:
table: table.innerHTML.replace(/<\s*img[^>]*>/gi,'');
这篇关于导出到Excel时删除HTML标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文