jsp页面导出成word,excel

来源:互联网 发布:淘宝买大麻种子犯法吗 编辑:程序博客网 时间:2024/05/22 09:01
1.word   
    var word = new ActiveXObject("Word.Application");
    var curTbl = document.getElementById("tabid");
    var doc = word.Documents.Add("",0,1);//不打开模版直接加入内容
    var Range=doc.Range(0,1); 
    var sel = document.body.createTextRange();

    sel.moveToElementText(curTbl);//
    sel.select();

    sel.execCommand("Copy");
    Range.Paste();
    word.Application.Visible = true;

2.excel
  var oXL = new ActiveXObject("Excel.Application");
  var oWB = oXL.Workbooks.Add();
  var oSheet = oWB.ActiveSheet;
  var sel=document.body.createTextRange();
  sel.moveToElementText(RS);
  sel.select();
  sel.execCommand("Copy");
  oSheet.Paste();
  oXL.Visible = true;
  idTmr = window.setInterval("Cleanup();",1);
  alert("Successful Output To Excel!");
 

//clear taskmgr
function Cleanup(){
   window.clearInterval(idTmr);
   CollectGarbage();//用于浏览器清除垃圾,释放缓存