您的位置:首页 > Web前端 > JavaScript

javascript页面内容导入Word和Excel

2011-09-08 10:58 561 查看
//导出到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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: