直接把table内容导出到word或excel

来源:互联网 发布:opera linux 64 编辑:程序博客网 时间:2024/04/29 18:19
2008-06-24 17:32

//js代码

//导出到excel
function AutomateExcel(){
var elTable = document.getElementById("datatable"); //要导出的table id。
var oRangeRef = document.body.createTextRange();
oRangeRef.moveToElementText(elTable);
oRangeRef.execCommand("Copy");
var appExcel = new ActiveXObject("Excel.Application");
appExcel.Workbooks.Add().Worksheets.Item(1).Paste();
appExcel.Visible = true;
appExcel = null;
}
//导出到word
//指定页面区域内容导入Word
function AllAreaWord()
{
var oWD = new ActiveXObject("Word.Application");
var oDC = oWD.Documents.Add("",0,1);
var orange =oDC.Range(0,1);
var elTable = document.getElementById("datatable");
var sel = document.body.createTextRange();
sel.moveToElementText(elTable);
//sel.select();
sel.execCommand("Copy");
orange.Paste();
oWD.Application.Visible = true;
oWD = null;
}

 

 

http://hi.baidu.com/kingdom031/blog/item/bec9168285cc0bba6c8119d5.html

原创粉丝点击