纯js不经后台导出excel实例

---------------------------------------------------------纯js不经后台导出excel实例 --------------------------------------------------------


一:代码如下

[html]  view plain copy
  1. <HTML >   
  2. <HEAD >   
  3. <TITLE >js导出excel </TITLE >   
  4. <SCRIPT LANGUAGE="javascript" >   
  5. function AutomateExcel() {   
  6.     var oXL = new ActiveXObject("Excel.Application"); //创建应该对象   
  7.     var oWB = oXL.Workbooks.Add();//新建一个Excel工作簿   
  8.     var oSheet = oWB.ActiveSheet;//指定要写入内容的工作表为活动工作表   
  9.     var table = document.all.data;//指定要写入的数据源的id   
  10.     var hang = table.rows.length;//取数据源行数   
  11.     var lie = table.rows(0).cells.length;//取数据源列数   
  12.     // Add table headers going cell by cell.   
  13.     for (i=0;i <hang;i++){//在Excel中写行   
  14.         for (j=0;j <lie;j++){//在Excel中写列   
  15.             //定义格式   
  16.             oSheet.Cells(i+1,j+1).Font.Bold = true;//加粗   
  17.             oSheet.Cells(i+1,j+1).Font.Size = 10;//字体大小   
  18.             if(table.rows(i).cells(j).innerHTML.toLowerCase().indexOf( " <img ")!=-1){//如果其HTML代码包括 <img   
  19.                 oSheet.Cells(i+1,j+1).Select();//选中Excel中的单元格   
  20.                 oSheet.Pictures.Insert(table.rows(i).cells(j).getElementsByTagName( "img ")[0].src);//插入图片   
  21.             }else{   
  22.                 oSheet.Cells(i+1,j+1).value = table.rows(i).cells(j).innerText;//向单元格写入值   
  23.             }   
  24.         }   
  25.     }   
  26.     oXL.Visible = true;   
  27.     oXL.UserControl = true;   
  28. }   
  29. </script>  
  30. </HEAD >   
  31. <BODY >   
  32. <table border="0" width="96%" cellspacing="0" cellpadding="0" align="center" class="Noprint">  
  33. <tr>  
  34. <td width="50%" height="13">·营运商信息管理</td>  
  35. <form method="post" action="?mydo=search" name="Form1">  
  36. <td width="50%" height="13" align="right">信息主题:<input type="text" name="KeyWord" size="20" value="" class="face">  
  37. <select size="1" name="types">  
  38. <option value="1" selected>编号</option>  
  39. <option value="2">单位名称</option>  
  40. <option value="3">单位地址</option>  
  41. <option value="4">法定代表人</option>  
  42. <option value="5">管理人员</option>   
  43. <option value="6">联系电话</option>   
  44. </select> <input type="submit" name="Submit" value="搜" class="button"></td>  
  45. </form>  
  46. </tr>  
  47. </table>  
  48. <div align="center">  
  49.   
  50. <table width="98%" border=1 cellpadding=0 bordercolor="#799AE1" class=tableBorder id="data" >  
  51. <tbody>  
  52. <tr>   
  53. <th height=21 width="87">编号</th>  
  54. <th width="87">单位名称</th>  
  55. <th width="301">地址</th>  
  56. <th height=21 width="121">法定代表人</th>  
  57. <th height=21 width="92">管理人员</th>  
  58. <th height=21 width="119">联系电话</th>  
  59. </tr>   
  60. <tr>   
  61. <td height=21 align="left" class=forumRow sytle="line-height:150%">50011500006</td>  
  62. <td height=21 align="left" class=forumRow sytle="line-height:150%">移动</td>  
  63. <td height=21 align="left" class=forumRow sytle="line-height:150%">http://www.52hai.com/2005</td>  
  64. <td class=forumRow height=21 sytle="line-height:150%" align="left">某某1</td>  
  65. <td class=forumRow height=21 sytle="line-height:150%" align="left">某某</td>  
  66. <td class=forumRow height=21 sytle="line-height:150%" align="left">25254255</td>  
  67. </tr>  
  68.   
  69. <tr>   
  70. <td height=21 align="left" class=forumRow sytle="line-height:150%">50011500005</td>  
  71. <td height=21 align="left" class=forumRow sytle="line-height:150%">铁通</td>  
  72. <td height=21 align="left" class=forumRow sytle="line-height:150%">铁通公司</td>  
  73. <td class=forumRow height=21 sytle="line-height:150%" align="left">某某</td>  
  74. <td class=forumRow height=21 sytle="line-height:150%" align="left">某某</td>  
  75. <td class=forumRow height=21 sytle="line-height:150%" align="left">25254254</td>  
  76. </tr>  
  77.   
  78. <tr>   
  79. <td height=21 align="left" class=forumRow sytle="line-height:150%">50011500004</td>  
  80. <td height=21 align="left" class=forumRow sytle="line-height:150%">广电</td>  
  81. <td height=21 align="left" class=forumRow sytle="line-height:150%">广播电视局</td>  
  82. <td class=forumRow height=21 sytle="line-height:150%" align="left">某某1</td>  
  83. <td class=forumRow height=21 sytle="line-height:150%" align="left">某某</td>  
  84. <td class=forumRow height=21 sytle="line-height:150%" align="left">25254254254</td>  
  85. </tr>  
  86.   
  87. <tr>   
  88. <td height=21 align="left" class=forumRow sytle="line-height:150%">50011500002</td>  
  89. <td height=21 align="left" class=forumRow sytle="line-height:150%">电信</td>  
  90. <td height=21 align="left" class=forumRow sytle="line-height:150%">电信公司</td>  
  91. <td class=forumRow height=21 sytle="line-height:150%" align="left">某某</td>  
  92. <td class=forumRow height=21 sytle="line-height:150%" align="left">某某</td>  
  93. <td class=forumRow height=21 sytle="line-height:150%" align="left">68331018</td>  
  94. </tr>  
  95.   
  96. <tr>   
  97. <td height=21 align="left" class=forumRow sytle="line-height:150%">50011500001</td>  
  98. <td height=21 align="left" class=forumRow sytle="line-height:150%">网通</td>  
  99. <td height=21 align="left" class=forumRow sytle="line-height:150%">网通公司</td>  
  100. <td class=forumRow height=21 sytle="line-height:150%" align="left">某某</td>  
  101. <td class=forumRow height=21 sytle="line-height:150%" align="left">某某</td>  
  102. <td class=forumRow height=21 sytle="line-height:150%" align="left">25254255</td>  
  103. </tr>  
  104. </table>   
  105. <input type="button" name="out_excel" onclick="AutomateExcel();" value="导出到excel" >   
  106. </BODY >   
  107. </HTML >  



页面展示如下


3、导出excel如下


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值