lqxue

常用链接

统计

book

tools

最新评论

html 导出excel

 

 
<head> 
 
<body>
 
<table class="dataintable" id='table22'>
        
<tbody><tr>
        
<th rowspan=2>雨量点</th><th>日期</th><th>日雨量</th><th>连续雨量</th><th colspan="2"><table><tbody><tr><th colspan="2">1小时最大</th><th></th></tr><tr><th>时间</th><th></th>        </tr></tbody></table></th>
        
<th>7</th> 
        
<th>8</th>
        
<th>9</th>
        
<th>10</th>
        
<th>11</th>
        
<th>12</th>
        
<th>13</th>
        
<th>14</th>
        
<th>15</th>
        
<th>16</th>
        
<th>17</th>
        
<th>18</th>
        
<th>19</th>
        
<th>20</th>
        
<th>21</th>
        
<th>22</th>
        
<th>23</th>
        
<th>24</th>
        
<th>1</th>
        
<th>2</th>
        
<th>3</th>
        
<th>4</th>
        
<th>5</th>
        
<th>6</th>
    
</tr>
    
<tr><td>繁昌大桥</td><td>2010-02-14</td><td> </td><td>连续雨量</td><td>时间</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td>龙山大桥</td><td>2010-02-14</td><td>34.0</td><td>连续雨量</td><td>时间</td><td>22.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>22.0</td><td>0.0</td><td>12.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td></tr><tr><td>鲤溪大桥</td><td>2010-02-14</td><td>33.0</td><td>连续雨量</td><td>时间</td><td>33.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>33.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td><td>0.0</td></tr><tr><td>海河大桥</td><td>2010-02-14</td><td> </td><td>连续雨量</td><td>时间</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td>汗江大桥</td><td>2010-02-14</td><td> </td><td>连续雨量</td><td>时间</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td>贸易大桥</td><td>2010-02-14</td><td> </td><td>连续雨量</td><td>时间</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td>鳖江特大桥</td><td>2010-02-14</td><td> </td><td>连续雨量</td><td>时间</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td>特别特山洞</td><td>2010-02-14</td><td> </td><td>连续雨量</td><td>时间</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td>长安大桥</td><td>2010-02-14</td><td> </td><td>连续雨量</td><td>时间</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td>东盛大桥</td><td>2010-02-14</td><td> </td><td>连续雨量</td><td>时间</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr><tr><td>繁昌大桥</td><td>2010-02-14</td><td> </td><td>连续雨量</td><td>时间</td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>

         
    
</tbody></table>
<table id="table1" width="90%" border="0" align="center" cellpadding="0" cellspacing="0" class="waikuang">
  
<tr>
    
<td width="6%" height="27" align="center" class="neikuangbold">序号</td>
    
<td width="10%" align="center" class="neikuangbold">时间</td>
    
<td width="20%" align="center" class="neikuangbold">单位</td>
    
<td width="18%" align="center" class="neikuangbold">项目</td>
    
<td width="10%" align="center" class="neikuangbold">结果等级</td>
    
<td width="10%" align="center" class="neikuangbold">检查机关</td>
    
<td width="8%" align="center" class="neikuangbold">记录人</td>
    
<td width="12%" align="center" class="neikuangbold">记录时间</td>
    
<td width="6%" align="center" class="neikuangbold">查看</td>
  
</tr>
  
<tr>
    
<td height="21" align="center" class="neikuang">1</td>
    
<td align="center" class="neikuang">1980-02-02</td>
    
<td align="center" class="neikuang">武警总队</td>
    
<td align="center" class="neikuang">安全用电检查</td>
    
<td align="center" class="neikuang">2222222</td>
    
<td align="center" class="neikuang">总部</td>
    
<td align="center" class="neikuang">主席</td>
    
<td align="center" class="neikuang">1980-02-02</td>
    
<td align="center" class="neikuang"><a href="aqChakanShow.html">查看</a></td>
  
</tr>
  
<tr>
    
<td height="21" align="center" class="neikuang">2</td>
    
<td align="center" class="neikuang">1980-02-02</td>
    
<td align="center" class="neikuang">武警总队</td>
    
<td align="center" class="neikuang">安全用电检查</td>
    
<td align="center" class="neikuang">2222222</td>
    
<td align="center" class="neikuang">总部</td>
    
<td align="center" class="neikuang">总理</td>
    
<td align="center" class="neikuang">1980-02-02</td>
    
<td align="center" class="neikuang"><a href="aqChakanShow.html">查看</a></td>
  
</tr>
  
</table>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
  
<tr>
    
<td height="25" align="right">首页 | 上一页 | 下一页 | 尾页</td>
  
</tr>
</table>
<table width="90%" align="center" border="0" cellpadding="0" cellspacing="0">
  
<tr>
    
<td width="50%" height="30" align="right" valign="bottom" style="padding-right:10px;"><input type="submit" name="Submit2" onclick="preview('table22')" value="打印当前页" class="waikuang" ></td>
    
<td width="50%" align="left" valign="bottom" style="padding-left:10px;"><input type="submit" name="Submit22" value="打印所有页"></td>
  
</tr>
</table>
</body>
<script language=javascript>
function preview(tableId) 

window.clipboardData.setData(
"Text",document.all(tableId).outerHTML);
try
{
var ExApp 
= new ActiveXObject("Excel.Application")
var ExWBk 
= ExApp.workbooks.add()
var ExWSh 
= ExWBk.worksheets(1)
ExApp.DisplayAlerts 
= false
ExApp.visible 
= true
}
  
catch(e)
{
alert(
"您的电脑没有安装Microsoft Excel软件!")
return false
}
 
 ExWBk.worksheets(
1).Paste;    
 }

</script>

</html>

And the important thing to notice here is the inline style for the table cell. This gets exported to Excel too as a background cell color. Cool, ain’t it?


So all inline styles are sent to excel too, this doesn’t happen with header style elements or external style sheets, so be careful.


One last thing to keep in mind is that this works only in IE. Code can be easily ported to the VBscript flavor. And if you have any problem, probably you should enable the “Initialize and script ActiveX controls not marked as safe” in the security options of IE.

posted on 2010-03-21 09:42 lqx 阅读(321) 评论(0)  编辑  收藏 所属分类: html


只有注册用户登录后才能发表评论。


网站导航: