原创  直接把jsp中table内容导出到word或excel 收藏

//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;

 

发表于 @ 2007年10月10日 19:33:00 | 评论( loading... ) | 编辑| 举报| 收藏

旧一篇:数据库中的树形结构 - JAVA 设计 (通用) | 新一篇:保护你的DLL和Code不被别人使用

Csdn Blog version 3.1a
Copyright © dongliheng