惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - chance

SQLServer 2008的数据库镜像实施笔记 报表服务器无法打印 - chance 人生值得学习的81句话 人件之名言警句 将 BLOB 值写入 SQL Server 时保留资源 - chance Reporting Service 在打印或预览时可能会导致出现空白页的原因 [翻译]使用ASP.NET2.0的ReportViewer查看RDLC报表 基于消息与.Net Remoting的分布式处理架构 C#程序实现动态调用DLL的研究 javascript事件列表解说 js 操作IE游览器 window.external... 微型项目实践感悟 - chance DELPHI:利用INI文件实现界面无闪烁多语言切换 Delphi - 利用INI文件实现界面多语言切换 SQLServer2000的数据库容量是多大? MessageBox对话框 项目经理是这样当的 SQL Server 存储过程的分页方案比拼 动态调用Webservice - chance
asp.net中如何打印ReportViewer报表 - chance - 博客园
chance · 2007-07-30 · via 博客园 - chance

     
.net 2.0中的新控件ReportViewer可以方便的制作并显示报表,但是它没有直接支持在网页中的打印。我在分析网页HTML源代码的基础上找到了直接打印的诀窍,先做成一个函数,方便直接使用。

    1.包含ReportViewer报表的网页的最终形式HTML DOM结构中,报表被放到一个<iframe>中,其id命名方式为:"ReportFrame"+报表控件id;
    2.报表内容被放到包含在1中的另一个<iframe>中,其id固定为:"report";
    3.为了实现打印,我们只要先获取内容<iframe>对象,设置焦点,然后调用print方法打印即可。
    4.已经封装好的javascript函数如下:

// JScript 文件
//
要打印ReportView报表的内容,只需要引用本文件,然后调用PrintReportView()函数即可。
//
例如:在某按钮的点击事件中包括代码,onclick="PrintReportView(window,'ReportViewerYsqd');"

//得到ReportView控件生成的客户端代码的报表内容区的FRAME对象
//
参数:objWindow——包含ReportView控件的window对象
//
      strReportViewerId——需要被打印的ReportViewer控件的ID
//
返回:得到的报表内容区FRAME对象;如果获取失败,返回null。
function GetReportViewContentFrame(objWindow,strReportViewerId)
{
    
var frmContent=null;    //报表内容区对象的FRAME对象
    var strFrameId="ReportFrame" + strReportViewerId ;  //asp.net自动生成的iframe 的id为:ReportFrame+报表控件id
    try
    
{
        frmContent
=window.frames[strFrameId].frames["report"];  //报表内容框架的id为report
    }

    
catch(e)
    
{
    }

    
return frmContent;
}


//打印ReportView控件中的报表内容
//
参数:objWindow——包含ReportView控件的window对象
//
      strReportViewerId——需要被打印的ReportViewer控件的ID
//
返回:(无)
function PrintReportView(objWindow,strReportViewerId)
{
    
var frmContent=GetReportViewContentFrame(objWindow,strReportViewerId);
    
if(frmContent!=null && frmContent!=undefined)
    
{
        frmContent.focus();
        frmContent.print();
    }

    
else
    
{
        alert(
"在获取报表内容时失败,无法通过程序打印。如果要手工打印,请鼠标右键点击报表内容区域,然后选择菜单中的打印项。");
    }

}

    5.下面是一个测试打印报表的完整例子:

<%@ Page Language="C#" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace
="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    
<title>无标题页</title>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
        
<rsweb:ReportViewer ID="rvYhqd" runat="server" Font-Names="Verdana" Font-Size="8pt" Height="484px" Width="718px">
            
<LocalReport ReportPath="公用程序yhqd.rdlc">
            
</LocalReport>
        
</rsweb:ReportViewer>
        
<br />
        
<asp:Button ID="Button1" runat="server" Text="打印" OnClientClick="return PrintReport();" />
    
</div>
    
</form>
    
<!--这里引用了包含打印报表函数的js文件-->
    
<script language="javascript" type="text/javascript" src="ReportView.js"></script>
    
<script language="javascript" type="text/javascript">
    
<!--
        
//打印报表
        function PrintReport()
        
{
            PrintReportView(window,
"rvYhqd");
            
return false;
        }

    
//-->
    </script>
</body>
</html>