
在项目,要实现把页面中的一个Table保存到Excel中,代码如下:
Html代码
<html>
<head>
<title>保存HTML中的Table到Excel中</title>
</head>
<body>
<h1>保存内容到Excel中</h1>
<table id='content'>
<tr><td>列1</td><td>列2</td></tr>
<tr><td>列1</td><td>列2</td></tr>
<tr><td>列1</td><td>列2</td></tr>
<tr><td>列1</td><td>列2</td></tr>
<tr><td>列1</td><td>列2</td></tr>
<tr><td>列1</td><td>列2</td></tr>
<tr><td>列1</td><td>列2</td></tr>
</table>
<a href="javascript:downloadfile('content')">保存文件</a>
<script language="javascript">
function downloadfile(id)
{
window.document.write(document.getElementById(id).outerHTML);
window.document.execCommand("SaveAs",false,"C:\\download.xsl");
history.go(-1);
}
</script>
</body>
</html>