如何在 ActiveReports 14 中向 PDF 渲染传递参数?

问题描述 投票:0回答:2

我正在实现一个 .Net Core 3.1 REST API,需要为给定合约生成 PDF 文件(合约 ID 已知)。

我在ActiveReports 14文档中采用了以下代码来生成示例报告,API中没有任何动态数据,并且工作正常:

// Provide the page report you want to render.
System.IO.FileInfo rptPath = new System.IO.FileInfo(@"..\..\PageReport1.rdlx");
GrapeCity.ActiveReports.PageReport pageReport = new GrapeCity.ActiveReports.PageReport(rptPath);

// Create an output directory.
System.IO.DirectoryInfo outputDirectory = new System.IO.DirectoryInfo(@"C:\MyPDF");
outputDirectory.Create();

// Provide settings for your rendering output.
GrapeCity.ActiveReports.Export.Pdf.Page.Settings pdfSetting = new GrapeCity.ActiveReports.Export.Pdf.Page.Settings();

// Set the rendering extension and render the report.
GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension pdfRenderingExtension = new GrapeCity.ActiveReports.Export.Pdf.Page.PdfRenderingExtension();
GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider outputProvider = new GrapeCity.ActiveReports.Rendering.IO.FileStreamProvider(outputDirectory, 
System.IO.Path.GetFileNameWithoutExtension(outputDirectory.Name));
            
// Overwrite output file if it already exists
outputProvider.OverwriteOutputFile = true;

pageReport.Document.Render(pdfRenderingExtension, outputProvider, pdfSetting);

但是,现在我需要修改报告以包含动态数据。根据合约ID选择动态数据。我认为我可以设法创建必要的数据源 (SQL) 和数据集,但首先我需要弄清楚,应如何传递合同 ID 以使数据源/数据集返回正确的数据。

有什么建议吗?

.net asp.net-core activereports
2个回答
0
投票

渲染前只需多一行:

pageReport.Document.Parameters["ContractId"].CurrentValue = yourContractId;

-1
投票

您可以从活动报表设计器添加参数并根据您的要求设置其属性。它将根据传递的参数获取数据。

© www.soinside.com 2019 - 2024. All rights reserved.