如何用js 将htm网页中的表格导出成word或excel? js 不能实现吧?ms 没有调用系统的权限! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 完全可以 ,js调 客户端 office 的权限一般还是有的相关命名空间:word.applicationexcel.application tantaiyizu 痴情客 等 级: 发表于:2008-02-01 15:26:332楼 得分:0 完全可以 ,js调 客户端 office 的权限一般还是有的 相关命名空间: word.application excel.application ? <script language="javascript"> function OpenWord(){ Layer1.style.border=0 ExcelSheet = new ActiveXObject('word.Application'); ExcelSheet.Application.Visible = true; var mydoc=ExcelSheet.Documents.Add('',0,1); myRange =mydoc.Range(0,1) var sel=Layer1.document.body.createTextRange() sel.select() Layer1.document.execCommand('Copy') sel.moveEnd('character') myRange.Paste(); location.reload() ExcelSheet.ActiveWindow.ActivePane.View.Type=9 } </script> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>网页上内容导出到word</title> </head> <body> <div id="Layer1" > <input type=button name='button_export' title='导出到word' onclick=OpenWord() value="下载到word"></div> </div> <table align="center" width="300" border="1" bordercolor="#2baeff" cellpadding="0" cellspacing="0" bgcolor="lightblue"> <Tr><Td>1</td><Td>2</td><Td>3</td></tr> <Tr><Td>4</td><Td>5</td><Td>6</td></tr> <Tr><Td>7</td><Td>8</td><Td>9</td></tr> </table> </body> </html> 接分 <script language="javascript"> function tableToExcel(tname) { if(confirm('是否要导出到excel?')!=0) { window.clipboardData.setData("Text",document.all(tname).outerHTML); try { ExApp = new ActiveXObject("Excel.Application") var ExWBk = ExApp.workbooks.add() var ExWSh = ExWBk.worksheets(1) ExApp.DisplayAlerts = false ExApp.visible = true } catch(e) { alert("导出没有成功!1.您的电脑没有安装Microsoft Excel软件!2.请设置Internet选项自定义级别,对没有标记安全级别的 ActiveX控件进行提示。") return false } ExWBk.worksheets(1).Paste; }else { return; } }</script>这个可以,当是要设置浏览器的安全级别 validate插件如何使用两个checkbox来验证 javascript:急等!!! 怪异问题,提交表单时,提示拒绝访问,并且file对象选择的内容被清空 -----》拖动层中的图片时候有卡的感觉,请高手指点! fckEditor到底怎么用啊,急急急急急急急 请问如何在JS里动态添加或者改变表单的事件 框架加载问题 求助!JavaScript,不会了. 怎样让用户必须输入两为数???????50分送!!!!! javascript 文件上传函数 jquery 添加onmouseover 事件 javascript有没有这样的函数
word.application
excel.application
痴情客
等 级:
发表于:2008-02-01 15:26:332楼 得分:0
完全可以 ,js调 客户端 office 的权限一般还是有的 相关命名空间:
word.application
excel.application
?
function OpenWord(){
Layer1.style.border=0
ExcelSheet = new ActiveXObject('word.Application');
ExcelSheet.Application.Visible = true; var mydoc=ExcelSheet.Documents.Add('',0,1);
myRange =mydoc.Range(0,1) var sel=Layer1.document.body.createTextRange()
sel.select()
Layer1.document.execCommand('Copy') sel.moveEnd('character')
myRange.Paste(); location.reload()
ExcelSheet.ActiveWindow.ActivePane.View.Type=9 } </script>
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>网页上内容导出到word</title> </head>
<body>
<div id="Layer1" >
<input type=button name='button_export' title='导出到word' onclick=OpenWord() value="下载到word"></div> </div> <table align="center" width="300" border="1" bordercolor="#2baeff" cellpadding="0" cellspacing="0" bgcolor="lightblue"> <Tr><Td>1</td><Td>2</td><Td>3</td></tr> <Tr><Td>4</td><Td>5</td><Td>6</td></tr> <Tr><Td>7</td><Td>8</td><Td>9</td></tr> </table>
</body> </html>
接分
function tableToExcel(tname) {
if(confirm('是否要导出到excel?')!=0)
{
window.clipboardData.setData("Text",document.all(tname).outerHTML);
try
{
ExApp = new ActiveXObject("Excel.Application")
var ExWBk = ExApp.workbooks.add()
var ExWSh = ExWBk.worksheets(1)
ExApp.DisplayAlerts = false
ExApp.visible = true
}
catch(e)
{
alert("导出没有成功!1.您的电脑没有安装Microsoft Excel软件!2.请设置Internet选项自定义级别,对没有标记安全级别的 ActiveX控件进行提示。")
return false
}
ExWBk.worksheets(1).Paste;
}else
{
return;
}
}
</script>
这个可以,当是要设置浏览器的安全级别