从RDLC XML字符串生成报告 [英] Generating report from rdlc xml string
问题描述
我生成报表时所面临的问题。
I'm facing an issue when generating reports.
我要生成动态使用的数据库中的所有数据,它的报告(源名称和RDLC报告店为XML字符串)
I should generate report dynamically using all data from database for it (source name and rdlc report that stores as xml string)
所以,我解决了问题,接下来方式:
So I solved problem next way:
- 创建与报告XML字符串本地RDLC文件;
-
设置文件的路径;
- Create local rdlc file with report xml string;
Set path to the file;
var rViewer = new ReportViewer();
rViewer.LocalReport.ReportPath = @"Path to the generated xml rdlc file";
var dataSource = new ReportDataSource("DataSourceName", data);
rViewer.LocalReport.DataSources.Add(dataSource);
我能在直接指定代码隐藏报告XML字符串,而不是生成RDLC文件并设置路径呢?你能推荐一个更好的办法?
Could I specify in the code-behind directly Report XML String instead of generating the rdlc file and set path to it? Could you recommend a better way?
感谢您
推荐答案
是的,你可以提供它StringReader使用LoadReportDefinition像这样的对象,
Yes, You can provide it a StringReader object using LoadReportDefinition like so,
private void Page_Load(object sender, System.EventArgs e)
{
NMBS.ViewModels.ViewModelReport Report = (Session["CurrentReport"] as NMBS.ViewModels.ViewModelReport);
ReportViewer.ProcessingMode = ProcessingMode.Local;
ReportViewer.PageCountMode = PageCountMode.Actual;
// Set report specifics.
ReportViewer.LocalReport.DisplayName = Report.Name;
ReportViewer.LocalReport.LoadReportDefinition(new System.IO.StringReader(Report.Definition));
foreach (ReportParameter Param in Report.Parameters)
{
ReportViewer.LocalReport.SetParameters(Param);
}
foreach (ReportDataSource Rds in Report.Data)
{
//Load Report Data.
ReportViewer.LocalReport.DataSources.Add(Rds);
}
ReportViewer.CurrentPage = Report.CurrentPage;
ReportViewer.Width = Report.Width;
// Refresh the reports.
ReportViewer.LocalReport.Refresh();
}
在哪里Report.Defintion是包含该报告的定义的XML字符串。
Where Report.Defintion is the String containing the XML of the Report's Definition.
这篇关于从RDLC XML字符串生成报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!