先在.aspx页面中添加如下代码
<script type="text/javascript">
//指定页面区域内容导入Word
function AllAreaWord() {
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(userList);//userList是属性id的值,例如想导出<div id="id1"/>中的内容,只需将userList换id1
sel.select();
sel.execCommand("Copy");
oRange.Paste();
oWD.Application.Visible = true;
}
</script>
<input type="button" onclick= "javascript:AllAreaWord(); " value= "导出页面到Word "/>
接着在IE中设置:Internet选项-安全-自定义级别-ActiveX控件和插件-对没有标记为安全的ActiveX控件
进行初始化和脚本运行选为提示(这个方法最大的缺点就是我们不可能要求客户端都去这样配,特殊的时候用此方法)