<%--
// ---------------------------------- 1 ---------------------------------- \\
<HTML>
<HEAD>
<TITLE>导出到excel</TITLE>
<META C>
<META C>
<META C>
<META C>
</HEAD>
<script language="javascript">
function exportExcel(tableid) {
if(typeof(EXPORT_OBJECT)!="object") {
document.body.insertAdjacentHTML("afterBegin","<OBJECT classid='clsid:0002E510-0000-0000-C000-000000000046'></Object>");
}
with(EXPORT_OBJECT) {
DataType = "HTMLData";
HTMLData =tableid.outerHTML;
try {
ActiveSheet.Export("d:\\表格.xls", 0);
alert('成功导出EXCEL表格!');
}
catch (e) {
alert('导出EXCEL表格失败,请确定已安装Excel2000(或更高版本),并且没打开同名xls文件');
}
}
}
</script>
<BODY>
<table>
<tr>
<td>第一个单元格</td>
<td>第二个单元格</td>
<td>第三个单元格</td>
</tr>
<tr>
<td>第四个单元格</td>
<td>第五个单元格</td>
<td>第六个单元格</td>
</tr>
</table>
<input type="button" value="导出EXCEL表格" >
</BODY>
</HTML>
// ---------------------------------- 2 ---------------------------------- \\
<!-- 导出到office2000版本的word或excel中 -->
<script language="javascript">
function tableToExcel() {
window.clipboardData.setData("Text",document.all('theObjTable').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;
}
function tableToWord() {
var oWD = new ActiveXObject("Word.Application");
var oDC = oWD.Documents.Add("",0,1);
var oRange =oDC.Range(0,1);
var sel = document.body.createTextRange();
sel.moveToElementText(theObjTable);
sel.select();
sel.execCommand("Copy");
oRange.Paste();
oWD.Application.Visible = true;
}
</script>
<table>
<tr>
<td>在html页面中</td>
<td>把网页中的表</td>
<td>格内容导入到</td>
<td>word中</td>
<td>也可以导入到excel</td>
</tr>
</table>
<input type="button" value="导入到excel" >
<input type="button" value="导入到word" >
// ---------------------------------- 3 ---------------------------------- \\
--%>
******************************************************************************************************
5.有关用js实现网页中的内容直接转化为excel的方法
******************************************************************************************************
复制代码 代码如下: