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

推荐订阅源

B
Blog RSS Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
G
GRAHAM CLULEY
Hacker News - Newest:
Hacker News - Newest: "LLM"
C
Cybersecurity and Infrastructure Security Agency CISA
Simon Willison's Weblog
Simon Willison's Weblog
Latest news
Latest news
C
CERT Recently Published Vulnerability Notes
T
Threatpost
V
Vulnerabilities – Threatpost
AWS News Blog
AWS News Blog
Blog — PlanetScale
Blog — PlanetScale
C
Cisco Blogs
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
U
Unit 42
The Register - Security
The Register - Security
T
The Blog of Author Tim Ferriss
Stack Overflow Blog
Stack Overflow Blog
The Hacker News
The Hacker News
AI
AI
Project Zero
Project Zero
Scott Helme
Scott Helme
S
Securelist
Vercel News
Vercel News
GbyAI
GbyAI
S
Security @ Cisco Blogs
I
InfoQ
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Check Point Blog
Forbes - Security
Forbes - Security
Google Online Security Blog
Google Online Security Blog
W
WeLiveSecurity
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
H
Heimdal Security Blog
G
Google Developers Blog
D
DataBreaches.Net
The Last Watchdog
The Last Watchdog
D
Docker
MyScale Blog
MyScale Blog
T
Tor Project blog
Cyberwarzone
Cyberwarzone
Recent Announcements
Recent Announcements
Microsoft Security Blog
Microsoft Security Blog
T
Tenable Blog
T
Threat Research - Cisco Blogs
Cisco Talos Blog
Cisco Talos Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 聂微东
月光博客
月光博客

博客园 - chance

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