asp.net 打印ReportViewer报表 rdlc报表
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("在获取报表内容时失败,无法通过程序打印。如果要手工打印,请鼠
相关文档:
最近正在做一个报表程序,也就是利用已经有的报表模板,将数据库里的数据填充进去后,客户端可以下载。
基本思想是这样的:1.在服务器端本地新建一个文件夹,专门用来存放临时的Excel表格
& ......
最终效果如下图:
-----------------------------------------------------------------------------------------------
样式部分:
<style type="text/css">
.anpager .cpb
{
& ......
1.代码后置
代码后置是微软的一项技术,也是我们编写ASP.NET常用的编码方式。具体方式就像页面文件(.aspx)和代码文件(.cs)两个文件相互关联
所构成的页面。一边情况下,.aspx文件中没有代码、只有空间和HTML代码,而.cs文件中编写相关的代码操作。
这样做的好处就是:使代码与页 ......
前台 aspx 文件:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="List.aspx.cs" Inherits="List" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<he ......
if(MyFile.PostedFile.ContentType != "image/gif"
&& MyFile.PostedFile.ContentType != "image/jpg"
&& MyFile.PostedFile.ContentType != "image/pjpeg"
&& &n ......