1.创建 表文件
在应用程序中创建一个名为 rptInvoice.rdlx 的 ActiveReports 表文件,使用的项目模板为 ActiveReports 页面 表。
2. 打开 表资源管理器,并按照以下信息创建 表数据源

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 选中 表文件,并设置以下属性:

4.2 从 VS 中将 Table 控件添加到 表设计界面,并按照以下列表设置相应属性:

最终设计界面如下:

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 levelif (chkEidt2.Checked)pdfExport1.Signature.CertificationLevel = GrapeCity.ActiveReports.Export.Pdf.Section.Signing.CertificationLevel.FormFillingAnnotations;elsepdfExport1.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();}
ActiveReports 表控件| 下载试用
ActiveReports 是一款专注于 .NET 平台的 表控件,全面满足 HTML5 / WinForm / ASP.NET / ASP.NET MVC / WPF 等平台下 表设计和开发工作需求,作为专业的 表工具为全球超过 300,000 开发人员提供了全面的 表开发服务。
如果您对我们的产品还有任何疑问,欢迎咨询在线客服>>
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!