zl程序教程

您现在的位置是:首页 >  工具

当前栏目

JS将表单导出成EXCEL的实例代码

2023-06-13 09:15:11 时间
复制代码代码如下:

<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
 <head>
 <title>newdocument</title>
 <metaname="generator"content="editplus"/>
 <metaname="author"content=""/>
 <metaname="keywords"content=""/>
 <metaname="description"content=""/>
 <SCRIPTLANGUAGE="javascript"> 
  <!-- 
  functionAutomateExcel() 
  { 
  //StartExcelandgetApplicationobject. 
  varoXL=newActiveXObject("Excel.Application"); 
  //Getanewworkbook. 
  varoWB=oXL.Workbooks.Add(); 
  varoSheet=oWB.ActiveSheet; 
  vartable=document.all.data; 
  varhang=table.rows.length;
  varlie=table.rows(0).cells.length; 
  //Addtableheadersgoingcellbycell. 
  for(i=0;i<hang;i++) 
  { 
  for(j=0;j<lie;j++) 
  { 
  //oSheet.Cells(i+1,j+1).Font.Bold=True 
  //oSheet.Cells(i+1,j+1).Font.Size=50 
  //oSheet.Cells(i+1,j+1).Alignment=2
  oSheet.Cells(i+1,j+1).value=table.rows(i).cells(j).innerText; 
  } 
  } 
  oXL.Visible=true; 
  oXL.UserControl=true; 
  } 
  //-->
  </SCRIPT>
 </head>

 
 <body>
  <tableborder="1"width="100%"id="data">
  <tr>
  <td> 姓名</td>
  <tdcolspan="2">年龄</td>
  <td>出生日期</td>
  </tr>
  <tr>
  <td>6</td>
  <td>25</td>
  <tdcolspan="2">8</td>
  </tr>
  <tr>
  <tdheight="22">1</td>
  <tdheight="22">2</td>
  <tdcolspan="2"height="22">4</td>
  </tr>
  </table>
<inputtype="button"name="out_excel"onclick="AutomateExcel();"value="导出到excel"class="notPrint">
 </body>
</html>