Chinaunix首页 | 论坛 | 博客
  • 博客访问: 925044
  • 博文数量: 264
  • 博客积分: 10107
  • 博客等级: 上将
  • 技术积分: 2455
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-09 16:34
文章分类

全部博文(264)

文章存档

2012年(1)

2011年(11)

2010年(128)

2009年(82)

2008年(42)

我的朋友

分类: 系统运维

2009-10-29 20:51:05

找了N久,终于找到了一个可用的办法,但会IE提出安全提示,但还能用。记录下来

在IE7下测试的安全提示,如图:

js:

function toexcel()
{
   
// start excel and get application object.
   var oxl = new ActiveXObject("excel.application");
   
// get a new workbook.
   var owb = oxl.workbooks.add();
   
var osheet = owb.activesheet;
   
var table = document.all.GridView1;
   
var hang = table.rows.length;
   
var lie = table.rows(0).cells.length;
   
// add table headers going cell by cell.
   for (i = 0; i < hang; i ++ )
   {
      
for (j = 0; j < lie; j ++ )
      {
         osheet.cells(i 
+ 1, j + 1).value = table.rows(i).cells(j).innerText;
      }
   }
   oxl.visible 
= true;
   oxl.usercontrol 
= true;
}
html:
<input type="button" name="button2" value="导出EXCEL" onclick="toexcel();" />
<table cellspacing="0" cellpadding="4" border="0" id="GridView1" style="color:#333333;border-collapse:collapse;">
        
<tr style="color:White;background-color:#507CD1;font-weight:bold;">
            
<th scope="col">姓名th><th scope="col">性别th><th scope="col">年龄th><th scope="col">电话1th>
        
tr><tr style="background-color:#EFF3FB;">
            
<td>张三0td><td>td><td>0td><td>0755-29102930td>
        
tr><tr style="background-color:White;">
            
<td>张三1td><td>td><td>1td><td>0755-29102931td>
        
tr><tr style="background-color:#EFF3FB;">
            
<td>张三2td><td>td><td>2td><td>0755-29102932td>
        
tr><tr style="background-color:White;">
            
<td>张三3td><td>td><td>3td><td>0755-29102933td>
        
tr><tr style="background-color:#EFF3FB;">
            
<td>张三4td><td>td><td>4td><td>0755-29102934td>
        
tr><tr style="background-color:White;">
            
<td>张三5td><td>td><td>5td><td>0755-29102935td>
        
tr>
    
table>
0
0
(请您对文章做出评价)
阅读(1506) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~