在ie中将表格导出excel

function table_to_excel(table_id){
  var oXL = new ActiveXObject("Excel.Application");
  var oWB = oXL.Workbooks.Add();
  var oSheet = oWB.ActiveSheet;
  var targetT = document.getElementById(table_id);  
  var Lenr = targetT.rows.length;
  for (i=0;i<Lenr;i++)
  {
   var Lenc = targetT.rows(i).cells.length;
   for (j=0;j<Lenc;j++)
   {
    node = targetT.rows(i).cells(j);
    if (node.innerText){
     oSheet.Cells(i+1, j+1).value = node.innerText;
    }else{
      oSheet.Cells(i+1,j+1).value = node.childNodes[0].value;
    }
   }
  }
  oXL.Visible = true;   
}

你可能感兴趣的:(IE,Excel,J#)