ActiveReports 支持多种格式的报表导出,包括PDF、Excel、Word、RTF、HTML、Text、TIFF以及其它图片格式,用户可以将它们应用到Windows Forms、Web、WPF、Silverlight等应用系统中。
在专业版的 ActiveReports 里,对PDF格式的数据输出又有了增强功能。现在用户可以将不可见的数字签名或者可见的文字图案加入到报表里。通过多种属性对数字签名进行个性化设置, 用数字签名验证报表作者,还可通过Certification Level 来设定用户访问权限。用时间印章功能建立第三方授权版本。这些新功能完全和Adobe的新安全机制兼容。
本文以客户订单为例演示如何将 ActiveReports 报表导出为各种格式。
1、创建报表文件
在应用程序中创建一个名为 rptInvoice.rdlx 的 ActiveReports 报表文件,使用的项目模板为 ActiveReports 页面报表。
2、打开报表资源管理器,并按照以下信息创建报表数据源
名称: | NWind_CHS |
类型: | Micorsoft OleDb Provider |
OLE DB 提供程序: | Microsoft.Jet.OLEDB.4.0 |
服务器或文件名称: | Data\NWind_CHS.mdb |
3、 添加数据集
在新建的 NWind_CHS 数据源上鼠标右键并选择添加数据集菜单项,添加以下两个数据集:
常规-名称:OrderDetails
查询-查询:
SELECT TOP 10 订单.订单ID, 订单.客户ID, 订单.订购日期, 产品.产品名称, 订单明细.数量, 订单明细.单价, 订单明细.折扣, 订单.货主城市, 订单.货主地址, 订单.货主名称, 订单.货主邮政编码, 客户.电话
FROM ((订单 INNER JOIN 订单明细 ON 订单.订单ID = 订单明细.订单ID) INNER JOIN 产品 ON 订单明细.产品ID = 产品.产品ID) INNER JOIN 客户 ON 订单.客户ID = 客户.客户ID
ORDER BY 订单.订购日期 DESC;
4、设计报表界面
4.1、选中报表文件,并设置以下属性:
常规-数据集名称: | OrderDetails |
分组: | 名称:FixedPage1_Group 表达式:=[订单ID] |
4.2、从 VS 中将 Table 控件添加到报表设计界面,并按照以下列表设置相应属性:
表格 | 属性 |
DataSetname | OrderDetails |
FixedSize | 19cm*15.75cm |
RepeatHeaderOnNewPage | True |
RepeatToFill | True |
单元格 | 属性 |
Cells[2,1] | Value:=RowNumber("Table1") |
Cells[2,2] | Value:=Fields!产品名称.Value |
Cells[2,3] | Value:=Fields!数量.Value |
Cells[2,4] | Value:=Fields!单价.Value |
Cells[2,5] | Value:=Fields!数量.Value * Fields!单价.Value |
合计单元格 | 属性 |
TextBox38 | Value:=Sum(Fields!数量.Value * Fields!单价.Value,"FixedPage1_Group") |
TextBox42 | Value:=ReportItems!TextBox38.Value * 0.17 |
TextBox39 | Value:=ReportItems!TextBox38.Value + ReportItems!TextBox42.Value |
最终设计界面如下:
5、添加报表导出功能
5.1、Excel导出代码:
protected void btnExcel_Click(object sender, EventArgs e)
{
GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("../") + "Reports/" + report + ".rdlx"));
_reportDef.Report.DataSources[0].DataSourceReference = Server.MapPath("../Data/NWind_CHS_Access.rdsx");
GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_reportDef);
GrapeCity.ActiveReports.Export.Excel.Section.XlsExport XlsExport1 = new GrapeCity.ActiveReports.Export.Excel.Section.XlsExport();
System.IO.MemoryStream ms = new System.IO.MemoryStream();
XlsExport1.FileFormat = GrapeCity.ActiveReports.Export.Excel.Section.FileFormat.Xlsx;
XlsExport1.Export(_reportRuntime, ms);
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition", Server.UrlPathEncode("attachment;filename=客户订单.xlsx"));
Response.BinaryWrite(ms.ToArray());
Response.End();
}
5.2、Word导出代码:
protected void btnWord_Click(object sender, EventArgs e)
{
GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("../") + "Reports/" + report + ".rdlx"));
_reportDef.Report.DataSources[0].DataSourceReference = Server.MapPath("../Data/NWind_CHS_Access.rdsx");
GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_reportDef);
GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension _renderingExtension = new GrapeCity.ActiveReports.Export.Word.Page.WordRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider _provider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
GrapeCity.ActiveReports.Export.Word.Page.Settings s = new GrapeCity.ActiveReports.Export.Word.Page.Settings();
s.UseMhtOutput = true;
_reportRuntime.Render(_renderingExtension, _provider, s);
Response.ContentType = "application/msword";
Response.AddHeader("content-disposition", Server.UrlPathEncode("attachment;filename=客户订单.doc"));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
_provider.GetPrimaryStream().OpenStream().CopyTo(ms);
Response.BinaryWrite(ms.ToArray()); Response.End();
}
5.3、常规PDF导出代码:
protected void btnPdf_Click(object sender, EventArgs e)
{
GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("../") + "Reports/" + report + ".rdlx"));
_reportDef.Report.DataSources[0].DataSourceReference = Server.MapPath("../Data/NWind_CHS_Access.rdsx");
GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_reportDef);
GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension _renderingExtension = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider _provider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
_reportRuntime.Render(_renderingExtension, _provider);
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", Server.UrlPathEncode("attachment;filename=客户订单.pdf"));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
_provider.GetPrimaryStream().OpenStream().CopyTo(ms);
Response.BinaryWrite(ms.ToArray());
Response.End();
}
5.4、HTML导出代码:
protected void btnHtml_Click(object sender, EventArgs e)
{
GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("../") + "Reports/" + report + ".rdlx"));
_reportDef.Report.DataSources[0].DataSourceReference = Server.MapPath("../Data/NWind_CHS_Access.rdsx");
GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_reportDef);
GrapeCity.ActiveReports.Export.Html.Page.HtmlRenderingExtension _renderingExtension = new GrapeCity.ActiveReports.Export.Html.Page.HtmlRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider _provider = new GrapeCity.ActiveReports.Rendering.IO.MemoryStreamProvider();
GrapeCity.ActiveReports.Export.Html.Page.Settings s = new GrapeCity.ActiveReports.Export.Html.Page.Settings();
s.StyleStream = false;
s.MhtOutput = false;
s.Fragment = false;
s.OutputTOC = true;
s.Mode = GrapeCity.ActiveReports.Export.Html.Page.RenderMode.Paginated;
_reportRuntime.Render(_renderingExtension, _provider, s);
Response.ContentType = "text/html";
Response.AddHeader("content-disposition", Server.UrlPathEncode("attachment;filename=客户订单.html"));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
_provider.GetPrimaryStream().OpenStream().CopyTo(ms);
Response.BinaryWrite(ms.ToArray());
Response.End();
}
5.5、 Text导出代码:
protected void btnText_Click(object sender, EventArgs e)
{
GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("../") + "Reports/" + report + ".rdlx"));
_reportDef.Report.DataSources[0].DataSourceReference = Server.MapPath("../Data/NWind_CHS_Access.rdsx");
GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_reportDef);
GrapeCity.ActiveReports.Export.Xml.Section.TextExport txtExport1 = new GrapeCity.ActiveReports.Export.Xml.Section.TextExport();
txtExport1.Encoding = Encoding.Unicode;
System.IO.MemoryStream ms = new System.IO.MemoryStream();
txtExport1.Export(_reportRuntime, ms);
Response.ContentType = "text/plain";
Response.AddHeader("content-disposition", Server.UrlPathEncode("attachment;filename=客户订单.txt"));
Response.BinaryWrite(ms.ToArray());
Response.End();
}
5.6、CSV导出代码:
protected void btnCSV_Click(object sender, EventArgs e)
{
GrapeCity.ActiveReports.PageReport _reportDef = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("../") + "Reports/" + report + ".rdlx"));
_reportDef.Report.DataSources[0].DataSourceReference = Server.MapPath("../Data/NWind_CHS_Access.rdsx");
GrapeCity.ActiveReports.Document.PageDocument _reportRuntime = new GrapeCity.ActiveReports.Document.PageDocument(_reportDef);
GrapeCity.ActiveReports.Export.Xml.Section.TextExport csvExport1 = new GrapeCity.ActiveReports.Export.Xml.Section.TextExport();
csvExport1.Encoding = Encoding.Unicode;
csvExport1.TextDelimiter = "\t";
csvExport1.SuppressEmptyLines = true;
System.IO.MemoryStream ms = new System.IO.MemoryStream();
csvExport1.Export(_reportRuntime, ms);
Response.ContentType = "text/plain";
Response.AddHeader("content-disposition", Server.UrlPathEncode("attachment;filename=客户订单.csv"));
Response.BinaryWrite(ms.ToArray());
Response.End();
}
5.7、高级PDF导出代码:
protected void btnExport_Click(object sender, EventArgs e)
{
GrapeCity.ActiveReports.PageReport report = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(Server.MapPath("../Reports/" + reportname + ".rdlx")));
report.Report.DataSources[0].DataSourceReference = "";
report.Report.DataSources[0].ConnectionProperties.DataProvider = "OLEDB";
report.Report.DataSources[0].ConnectionProperties.ConnectString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};", Server.MapPath("../Data/NWind_CHS.mdb"));
GrapeCity.ActiveReports.Document.PageDocument document = new GrapeCity.ActiveReports.Document.PageDocument(report);
GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport pdfExport1 = new GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport();
switch (C1Tabs1.Selected)
{
case 0:
break;
case 1:
pdfExport1.Security.Encrypt = true;
pdfExport1.Security.Use128Bit = true;
if (txtPwd.Text.Length > 0)
pdfExport1.Security.UserPassword = txtPwd.Text;
pdfExport1.Security.Permissions = GrapeCity.ActiveReports.Export.Pdf.Section.PdfPermissions.None;
if (chkCopy.Checked)
pdfExport1.Security.Permissions |= GrapeCity.ActiveReports.Export.Pdf.Section.PdfPermissions.AllowCopy;
if (chkEidt1.Checked)
{
pdfExport1.Security.Permissions |= GrapeCity.ActiveReports.Export.Pdf.Section.PdfPermissions.AllowFillIn;
pdfExport1.Security.Permissions |= GrapeCity.ActiveReports.Export.Pdf.Section.PdfPermissions.AllowModifyAnnotations;
pdfExport1.Security.Permissions |= GrapeCity.ActiveReports.Export.Pdf.Section.PdfPermissions.AllowModifyContents;
}
if (chkPrint.Checked)
pdfExport1.Security.Permissions |= GrapeCity.ActiveReports.Export.Pdf.Section.PdfPermissions.AllowPrint;
break;
case 2:
// ImageText signature.
pdfExport1.Signature.VisibilityType = GrapeCity.ActiveReports.Export.Pdf.Section.Signing.VisibilityType.ImageText;
// Bounds (Container of Text & Image).
pdfExport1.Signature.Stamp.Bounds = new RectangleF(0, 0, 4, 1);
// Text area.
pdfExport1.Signature.Stamp.TextAlignment = GrapeCity.ActiveReports.Export.Pdf.Section.Signing.Alignment.Left;
pdfExport1.Signature.Stamp.Font = new Font("Comic Sans MS", 8, FontStyle.Regular);
// Note: Specify (x, y) in relative coordinate from Bounds top-left.
pdfExport1.Signature.Stamp.TextRectangle = new RectangleF(1, 0, 3, 1);
// Image area.
pdfExport1.Signature.Stamp.Image = System.Drawing.Image.FromFile(Server.MapPath("../Resources/Grapecity_powertools_bg.png"));
pdfExport1.Signature.Stamp.ImageAlignment = GrapeCity.ActiveReports.Export.Pdf.Section.Signing.Alignment.Center;
// Note: Specify (x, y) in relative coordinate from Bounds top-left.
pdfExport1.Signature.Stamp.ImageRectangle = new RectangleF(0, 0, 1, 1);
// Set certificate & password.
pdfExport1.Signature.Certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(Server.MapPath("../Resources/ActiveReports6.pfx"), "123456");
// set the certifiation level
if (chkEidt2.Checked)
pdfExport1.Signature.CertificationLevel = GrapeCity.ActiveReports.Export.Pdf.Section.Signing.CertificationLevel.FormFillingAnnotations;
else
pdfExport1.Signature.CertificationLevel = GrapeCity.ActiveReports.Export.Pdf.Section.Signing.CertificationLevel.NoChangesAllowed;
//Signature items.
pdfExport1.Signature.Contact = new GrapeCity.ActiveReports.Export.Pdf.Section.Signing.SignatureField<string>(txtEmail.Text, true);
if (chkDate.Checked)
pdfExport1.Signature.SignDate = new GrapeCity.ActiveReports.Export.Pdf.Section.Signing.SignatureField<System.DateTime>(System.DateTime.Now, true);
break;
default:
break;
}
System.IO.MemoryStream ms = new System.IO.MemoryStream();
pdfExport1.Export(document,ms);
Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", Server.UrlPathEncode("attachment;filename=客户订单.pdf"));
Response.BinaryWrite(ms.ToArray()); Response.End();
}
在线演示及源码下载地址:
http://www.gcpowertools.com.cn/products/activereports_demo.htm
相关推荐
ActiveReports 报表三小时入门视频(一):安装产品、了解产品基本信息ActiveReports 报表三小时入门视频(二):在项目中使用 ActiveReportsActiveReports 报表三小时入门视频(三):设计不同类型
注册成功后,就可以在项目中创建新的ActiveReports报表了。 最后,关于汉化界面,`汉化ActiveReports 2.0界面.txt`文件可能包含的是汉化步骤或汉化资源。对于非英文环境下的开发者来说,这非常有用。通常,汉化步骤...
通过这三小时的视频教程,开发者将获得足够的基础,能够使用ActiveReports 14创建出功能丰富、交互性强的报表,满足业务需求。无论你是初次接触报表设计,还是希望提升现有技能,这个教程都将是一次宝贵的学习体验。...
ActiveReports 9不仅提供了强大的报表设计能力,还支持自定义样式、数据源连接、导出格式等多种功能,使得开发者能够构建出满足各种需求的高质量报表应用。通过深入学习和实践,你可以充分发掘ActiveReports 9的潜力...
通过以上步骤,你将能够构建并预览一个基本的ActiveReports报表,这仅为入门级操作,ActiveReports的强大之处在于其深度的自定义能力和广泛的格式支持,能够满足复杂报表需求。开发者可以通过深入学习其文档和实践,...
ActiveReports(以下简称AR)是一款日本开发的报表打印组件,类似于vs2003自带的那个CrystalReports(即水晶报表,简称CR),虽然普及率没CR高,但是在很多对日项目中却普遍使用,而网上资料几乎都是CR,AR的中文...
本资源包含"ActiveReports 6 Setup.exe"安装程序以及"ActiveReports 报表控件软件 V6.0 使用指南.pdf"用户手册,旨在帮助用户全面了解和使用ActiveReports 6中文版。 首先,ActiveReports 6的核心特性在于它的设计...
### ActiveReports中文使用指南:安装与基础应用 #### 一、引言 ActiveReports (简称 AR) 是一款功能强大的报表开发工具,适用于 .NET 平台。它为开发者提供了丰富的功能,包括但不限于自定义报表设计、多种数据源...
在这个特定的场景中,我们关注的是如何使用ActiveReports 14版本在Web端连接Oracle数据库并展示报表。本文将深入探讨这个主题,为那些在web项目中使用ActiveReports 14并需要与Oracle数据库交互的开发者提供指导。 ...
ActiveReports是一款强大的报表工具,专为开发者设计,用于在各种应用程序中创建、设计和呈现复杂的报表。在ASP.NET MVC框架中使用ActiveReports,可以轻松实现HTML5格式的报表,提供丰富的用户交互体验,并且支持...
通过《ActiveReports for .NET User Guide》,开发者不仅可以学习到如何使用ActiveReports的各种特性,还能掌握报表设计的最佳实践,从而在实际项目中实现高效、专业的报表开发。无论你是初学者还是经验丰富的开发者...
"ActiveReports系列.rar" 可能是一个包含多个版本或者扩展资料的压缩包,可能包含ActiveReports的其他版本、示例代码、教程或其他相关文档,对于深入学习和了解ActiveReports的功能和使用方法非常有帮助。...
ActiveReports 6.0 是一款强大的报表开发工具,专为软件开发者设计,旨在简化报表的创建、管理和分发过程。这款第三方报表工具以其易用性和高效性受到开发者的广泛好评,是项目中不可或缺的组件之一。 ...
这个安装包包含了创建、设计和嵌入到应用程序中的报表解决方案所需的所有组件。ActiveReports 6.0旨在为开发者提供高效、灵活且功能丰富的报告设计体验。 在ActiveReports 6.0中,主要包含以下关键知识点: 1. **...
在这个入门教程中,我们将探讨其地图控件的组成元素以及如何使用这些元素来构建交互式地图。 首先,地图标题(Title)是地图控件的重要组成部分,用于描述地图所代表的业务或区域。在报表设计界面中,可以通过选择...
4. 产品入门必读.pdf: 这是一份详尽的产品入门教程,为用户提供逐步学习如何使用ActiveReportsJS 2.2预览版的指导,帮助开发者快速掌握报表设计和编辑的基本操作。 5. dist: 这个目录包含了编译后的可执行文件和库...