展开全部
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<h1>通过javascript弄的,表格的样式是怎么样的,导出的excel就是怎么样的,用到了ActiveX,确保IE允许运行未标记的ActiveX</h1>
<input type="button" onclick="ExportExcel()" value="导出到excel">
<table id="table1">
<tr>
<td>asdfas<td>
<td>asdfas2<td>
<td>asdfas3<td>
</tr>
<tr>
<td>asdfas<td>
<td>asdfas2<td>
<td>asdfas3<td>
</tr>
</table>
</BODY>
<script>
function ExportExcel() {
window.clipboardData.setData("Text",document.getElementById('table1').outerHTML);
try {
var ExApp = new ActiveXObject("Excel.Application")
var ExWBk = ExApp.workbooks.add()
var ExWSh = ExWBk.worksheets(1)
ExApp.DisplayAlerts = false
ExApp.visible = true
} catch(e) {
alert("您的电脑没有安装Microsoft Excel软件!")
return false
}
ExWBk.worksheets(1).Paste;
}
</script>
</HTML>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<h1>通过javascript弄的,表格的样式是怎么样的,导出的excel就是怎么样的,用到了ActiveX,确保IE允许运行未标记的ActiveX</h1>
<input type="button" onclick="ExportExcel()" value="导出到excel">
<table id="table1">
<tr>
<td>asdfas<td>
<td>asdfas2<td>
<td>asdfas3<td>
</tr>
<tr>
<td>asdfas<td>
<td>asdfas2<td>
<td>asdfas3<td>
</tr>
</table>
</BODY>
<script>
function ExportExcel() {
window.clipboardData.setData("Text",document.getElementById('table1').outerHTML);
try {
var ExApp = new ActiveXObject("Excel.Application")
var ExWBk = ExApp.workbooks.add()
var ExWSh = ExWBk.worksheets(1)
ExApp.DisplayAlerts = false
ExApp.visible = true
} catch(e) {
alert("您的电脑没有安装Microsoft Excel软件!")
return false
}
ExWBk.worksheets(1).Paste;
}
</script>
</HTML>
追问
asdfas
asdfas2
asdfas3
asdfas
asdfas2
asdfas3
这一块的值我不想让他固定怎么写呢?而且直接告诉我没有安装office,
追答
补充回答:
你把查出来的数据放到table里面就行了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询