SQL 查询数据打印并导出EXECL

本文介绍了如何通过SQL查询将数据导出为Excel文件,并提供了多种网页中实现打印预览和导出Excel的方法,包括利用JavaScript、iframe和按钮事件等技术。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 导出提交的页面加上:
response.contenttype= "application/msexcel "
response.addheader   "content-disposition ", "attachment;filename=export.xls "
打印: <span   id=bt1> <input   type= "submit "   name= "Submit "   value= "打印 "onClick= "javascript:bt1.innerHTML= ' ';window.print();return   false; "   style= "cursor:hand "> </span>

 

 

<%
if   request( "action ")= "down "   then
response.ContentType   = "application/vnd.ms-excel "
Response.AddHeader   "Content-Disposition ",   "attachment;   filename=1.xls "
end   if
%>
<a   href= "?action=down "> 保存成excel </a>

 

 

打印预览框架里的内容

<OBJECT classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2" height="0" id="WebBrowser" width="0"></OBJECT>
<input name="Button" onClick="document.all.hiddenframe.ExecWB(7,1);" type="button" value="打印预览">
<iframe frameborder="0" height="10%" width="100%" name="hiddenframe" src="test.htm"></iframe>

 

<body>
<input onclick='prn()' type=button value=print_Iframe> <br>
<iframe id=mxh src="d:/hhh.htm"> </iframe>
<script>
function prn()
{
var win=window.open("about:blank")
win.moveTo(1200,1200)
win.location=document.all.mxh.src
win.print()
}
</script>

 

 

存在一个页面:par.aspx

存在一个iframe包含于par.aspx
iframe.id= "prnf "
iframe.name= "prnf "
iframe.src= "sprn.html "

 

<input   onclick= "window.frames[ 'prnf '].focus();window.frames[ 'prnf '].print(); ">

 

 

 

<SCRIPT    LANGUAGE=javascript> 
  function    button1_onclick() 
  { 
    var    odoc=window.right.document; 
    var    r=odoc.body.createTextRange(); 
    var    stxt=r.htmlText; 
    alert(stxt) 
    var    pwin=window.open("","print"); 
    pwin.document.write(stxt); 
    pwin.print(); 
  }  
  function    button1_onclick2()
  { 
    var    oWin=window.open("") 
    oWin.document.write(top.right.document.body.outerHTML) 
    oWin.print(); 
    oWin.location.reload(); 
    oWin.close();
  }
</SCRIPT>
<input type="button" value="按钮1" onClick="button1_onclick()"/> 
<input type="button" value="按钮2" onClick="button1_onclick2()"/> 
<iframe frameBorder="0" id="right" name="right2" scrolling="auto" src="panel_index.asp" style="HEIGHT: 96%; VISIBILITY: inherit; WIDTH: 100%; Z-INDEX: 1"> </iframe>

 

 

 

<head>  
  <title>打印确认</title>  
  <style   media="print">  
  .noprint   {   display:   none   }  
  </style>  
  </head>  
  <body>  
  <object   id="factory"   style="display:none"   viewastext   classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814"   codebase="http://www.meadroid.com/scriptx/ScriptX.cab#Version=5,60,0,360"></object>  
  <script   defer>  
  function   window.onload()   {  
      //factory.printing.paperSize   =   "A3"  
      factory.printing.header   =   ""  
      factory.printing.footer   =   ""  
      factory.printing.portrait   =   false  
      idPrint1.disabled   =   false;   //   enable   UI   button  
      idPrint2.disabled   =   false;  
      idPrint3.disabled   =   false;  
      idPrint4.disabled   =   false;  
      factory.printing.leftMargin   =   0.75  
      factory.printing.topMargin   =   1.5  
      factory.printing.rightMargin   =   0.75  
      factory.printing.bottomMargin   =   1.5  
      }  
  </script>  
  <div   class=noprint>  
      <input   id="idPrint1"   type="button"   value="打印本页"  
    onclick="factory.printing.Print(false)">  
      <input   id="idPrint2"   type="button"   value="页面设置"  
    onclick="factory.printing.PageSetup()">  
      <input   id="idPrint3"   type="button"   value="打印预览"  
    onclick="factory.printing.Preview()">  
      <input   id="idPrint4"   type="button"  
    onclick="window.close()"   value="关闭窗口">  
  </div>  
  <br/>  
  <table   width="720"   border="0"   cellspacing="0"   cellpadding="0"   align="center"   >  
      <tr>    
          <td     bgcolor="#0099ff">  
        这里是你要打印的内容,上面的按钮不会被打印出来<br/>  
        factory.printing.paperSize   =   "A3"  
        </td>  
  </tr></table></body>   

 

 

 

<!--这里调用控件ScriptX.cab-->
<object id="factory" style="DISPLAY: none" viewastext classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="http://www.a.com/smsx.cab#Version=6,3,434,26"></object>
<SCRIPT defer>
//用于设置打印参数
function printBase() {
factory.printing.footer = "页眉"   //页眉
factory.printing.footer = "页脚"   //页脚
factory.printing.portrait = false   //true为纵向打印,false为横向打印
factory.printing.leftMargin = 1.5   //左页边距
factory.printing.topMargin = 0.5   //上页边距
factory.printing.rightMargin = 0.5   //右页边距
factory.printing.bottomMargin = 1.0   //下页边距
}

//用于调用设置打印参数的方法和显示预览界面
function printReport(){
        printBase();
        //window.print();
        factory.printing.Preview();
}

//使界面最大化
maxWin();
function maxWin()
{
      var aw = screen.availWidth;
      var ah = screen.availHeight;
      window.moveTo(0, 0);
      window.resizeTo(aw, ah);
}
</SCRIPT>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" bordercolor="#FFFFFF">
   <tr bordercolor="#FFFFFF">
     <td >
        <table width="70%" border="0" cellspacing="0" cellpadding="2" align="center">
          <tr>
            <td align="center"><font size="5" face="宋体"><b>查询打印</b></font></td>
          </tr>
          <tr>
            <td align="center">
              <div id="divReport" name="divReport">
              <input type="button" name="cmdPRINT" id="cmdPRINT" onclick="printReport()" value="打印">
              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <input type="button" onclick="window.close();"   value="关闭">
              </div>
            </td>
          </tr>
        </table>
    </td>
   </tr>
</table>
</body>
</html>


 

 

 

 

<script   language= "javascript ">    
  function   printsetup(){    
  //   打印页面设置    
  wb.execwb(8,1);    
  }    
  function   printpreview(){    
  //   打印页面预览    
        
  wb.execwb(7,1);    
         
        
  }    

  function   printit()    
  {    
  if   (confirm( '确定打印吗? '))   {    
  wb.execwb(6,6)    
  }    
  }    
   </script>    
</head>    
<body>    
<OBJECT   classid= "CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 "   height=0   id=wb   name=wb   width=0> </OBJECT>
<table>
<tr> <td> 数据 </td> </tr>
<tr> <td> 数据 </td> </tr>
<tr> <td> 数据 </td> </tr>
<tr> <td> 数据 </td> </tr>
<tr> <td> 数据 </td> </tr>
<tr> <td> 数据 </td> </tr>
</table>  
<input   type=button   name=button_print   value= "打印 "     onclick= "javascript:printit() ">    
<input   type=button name=button_setup   value= "打印页面设置   "onclick= "javascript:printsetup(); ">    
<input   type=button name=button_show   value= "打印预览 "   onclick= "javascript:printpreview(); ">    
<input   type=button   name=button_fh   value= "关闭 "     onclick= "javascript:window.close(); ">

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值