table导出Excel、Word的方法---Js下的实现

在公司做项目时用的这个方法,感觉还不错,蛮简单的。(运行于内网IE6上)

//导出Excel
function AllAreaExcel()    
 {
  var oXL = new ActiveXObject("Excel.Application"); 
  var oWB = oXL.Workbooks.Add(); 
  var oSheet = oWB.ActiveSheet;  
  var sel=document.body.createTextRange();
  sel.moveToElementText(PrintA);  //PrintA是table的id
  sel.select();
  sel.execCommand("Copy");
  oSheet.Paste();
  oXL.Visible = true;
 }

//导出Word
 function AllAreaWord()
 {
  var oWD = new ActiveXObject("Word.Application");
  var oDC = oWD.Documents.Add("",0,1);
  var oRange =oDC.Range(0,1);
  var sel = document.body.createTextRange();
  sel.moveToElementText(PrintA);   //PrintA是table的id
  sel.select();
  sel.execCommand("Copy");
  oRange.Paste();
  oWD.Application.Visible = true;
 }








你可能感兴趣的:(JavaScript,Excel)