表格导出EXCEL

<TABLE   id="outtable"   name="outtable" border=1>  
  <TR>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  </TR>  
  <TR>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  </TR><TR>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  </TR><TR>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  </TR><TR>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  <TD>asdf</TD>  
  </TR>  
  </TABLE>  
<input   type="button"   name="out_excel"   onclick="AutomateExcel();"

 

<SCRIPT   LANGUAGE="javascript">
  function   AutomateExcel()
  {
  var   oXL   =   new   ActiveXObject("Excel.Application");
  var   oWB   =   oXL.Workbooks.Add();
  var   oSheet   =   oWB.ActiveSheet;
  var   hang   =   outtable.rows.length;

  var   lie   =   outtable.rows(0).cells.length;

  for   (i=0;i<hang;i++)
  {
  for   (j=0;j<lie;j++)
  {
  oSheet.Cells(i+1,j+1).value   =   outtable.rows(i).cells(j).innerText;
  }

  }
  oXL.Visible   =   true;
  oXL.UserControl   =   true;
  }
  </SCRIPT>

posted @ 2009-06-30 16:57  夜色狼  阅读(192)  评论(0编辑  收藏  举报