学习网考试学习资料

Gzu521.com

JavaScript Web页面内容导出到Word、Excel

Javascript教程   点击:次   发布时间:2005-11-14   【字体: 】   来源:Gzu521.com
Gzu521.com我的学习网

<html>
  <head>
    <title>web页面导出为excel文档的方法
    </title>
  </head>
<body>
<br>
<table id = "printa" width="100%" border="1" cellspacing="0" cellpadding="0" bgcolor = "#61ff13">
<tr style="text-align : center;">
 <td>单元格a</td>
 <td>单元格a</td>
 <td>单元格a</td>
 <td>单元格a</td>
</tr>
<tr>
 <td colspan=4 style="text-align : center;"><font color="blue" face="verdana">单元格合并行a</font></td>
</tr>
</table>
<br>
<table id = "printb" width="100%" border="1" cellspacing="0" cellpadding="0">
<tr style="text-align : center;">
 <td>单元格b</td>
 <td>单元格b</td>
 <td>单元格b</td>
 <td>单元格b</td>
</tr>
<tr>
 <td colspan=4 style="text-align : center;">单元格合并行b</td>
</tr>
</table>
<br><br><br>
<input type="button" onclick="Javascript:allareaword();" value="导出页面指定区域内容到word">
<input type="button" onclick="JavaScript:allareaexcel();" value="导出页面指定区域内容到excel">
<input type="button" onclick="javascript:cellareaexcel();" value="导出表单单元格内容到excel">
<script language="javascript">
 //指定页面区域内容导入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);
  sel.select();
  sel.execcommand("copy");
  osheet.paste();
  oxl.visible = true;
 }
 //指定页面区域“单元格”内容导入excel
 function cellareaexcel()
 {
  var oxl = new activexobject("excel.application");
  var owb = oxl.workbooks.add();
  var osheet = owb.activesheet;
  var lenr = printa.rows.length;
  for (i=0;i<lenr;i++)
  {
   var lenc = printa.rows(i).cells.length;
   for (j=0;j<lenc;j++)
   {
    osheet.cells(i+1,j+1).value = printa.rows(i).cells(j).innertext;
   }
  }
  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);
  sel.select();
  sel.execcommand("copy");
  orange.paste();
  owd.application.visible = true;
  //window.close();
 }
</script>
</body></html> ! W+XY|}IN7aY^|u [ 本 资 料 来 源 于 贵 州 学 习 网 网页设计Javascript教程 http://Www.gzU521.com ] ! W+XY|}IN7aY^|u

责任编辑:gzu521

网页设计分类
HTML教程
CSS教程
Javascript教程
Dreamweaver教程
FrontPages教程
FireWorks教程
Flash教程
PhotoShop教程
建站知识
分类推荐信息
更多...
大类最新文章
更多...