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

来源:百度文库 编辑:神马文学网 时间:2024/04/27 17:08:34
//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;
}