从 HTML 表导出为 excel 显示带有标记的所有表内容
Export as excel from HTML table shows all the table contents with tags
>我目前在将 html 表转换为 excel 时遇到问题,但每当我检查文件时,它只用一行填充,即带有表格的 HTML 标签。我正在开发的 chrome 扩展有表,但没有 id 和类,所以我使用 table:nth-child(2) 来定位它。
这是我的代码:
var textbox = document.getElementsByName('regular')[0];
console.log(textbox);
var para = document.createElement("input");
var t = document.createTextNode("Show Password");
para.setAttribute("type", "button");
para.setAttribute("id", "btnExport");
para.setAttribute("value","Export Table data into Excel");
textbox.parentElement.appendChild(para);
$("#btnExport").click(function (e) {
window.open('data:application/vnd.ms-excel,' + $('table:nth-child(2)').html());
e.preventDefault();
});
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$(document).ready(function () {
$("#btnExport").click(function (e) {
window.open('data:application/vnd.ms-excel,' + $('#dvData').html());
e.preventDefault();
});
});
</script>
</head>
<body>
<input type="button" id="btnExport" value="Export" />
<div id="dvData">
<table>
<tr>
<th>Column One</th>
<th>Column Two</th>
<th>Column Three</th>
</tr>
<tr>
<td>row1 Col1</td>
<td>row1 Col2</td>
<td>row1 Col3</td>
</tr>
<tr>
<td>row2 Col1</td>
<td>row2 Col2</td>
<td>row2 Col3</td>
</tr>
<tr>
<td>row3 Col1</td>
<td>row3 Col2</td>
<td><a href="http://www.jquery2dotnet.com/">http://www.jquery2dotnet.com/</a>
</td>
</tr>
</table>
</div>
</body>
</html>
相关文章:
- Brightcove获取/显示HTML中的当前视频标题和描述
- HTML 标记未在 AngularJS ckEditor 中应用,而是在 Ediator 中显示 HTML 元素标记代码
- 使用jqLite隐藏和显示html元素
- 如何在不打断标记的情况下突出显示html字符串中的文本
- JS来显示HTML标记
- 如果javascript打开/关闭,则隐藏和显示html代码
- 用javascript显示html表
- 显示HTML代码块
- Regex有助于突出显示html中匹配文本的角度过滤器
- 为什么WebBrowser控件在保存后不能正确显示HTML
- 如何通过ibmworklight中的sql适配器从db2中检索或显示html页面上的数据?android混合应用程序开发
- 如何使用window.showModalDialog()显示HTML内容
- JavaScript if else 语句来显示 html 标签
- 使用 js 函数显示 HTML 表单的结果
- 如何在不点击的情况下突出显示 HTML 中的文本
- 如何隐藏和显示 html 输入文本和段落
- 使用 javascript 解析和显示 HTML 音频当前时间
- 有什么方法可以在HTML页面中显示HTML代码吗
- 在自动完成jqueryUi中显示html
- 单击并用CTRL+C复制值时高亮显示html表格单元格