Stimulsoft Reports.Net开发者常见Q&A——编译报表

发布时间 : 2015-12-14 10:25:51.000|阅读 2229 次

概述:本片文章主要介绍Stimulsoft Reports.Net开发者在处理编译报表时遇到的常见问题及解决方案。

相关链接:

< Stimulsoft Reports.Net v2015.3最新版本下载>

1.如何将报表编译到汇编里?

使用Compile方法:

C#

//编译到文件
report.Compile("MyReport.dll");
//编译到流
report.Compile(stream);

VB

'编译到文件
Report.Compile("MyReport.dll")
'编译到流
Report.Compile(stream)

此外,你还可以从报表设计器将报表保存到汇编。

2.怎么将汇编里的报表加载到内存里面?

当你使用StiReport.GetReportFromAssembly方法时,报表被加载到每一个案例的内存中。这在当你从汇编加载报表需要指定附加参数时可避免:

C#

StiReport report = StiReport.GetReportFromAssembly("MyReport.dll", true);

VB

Dim Report As StiReport = StiReport.GetReportFromAssembly("MyReport.dll", True)

需记住的是在这种情况下.dll文件将被封锁,直到应用程序运行起来。

3.怎么使用编译后的报表汇编?

在报表设计器中你可以将你的报表保存为汇编(DLL文件)。你可以通过下面的代码在你的应用程序中使用该类报表:

C#

StiReport report = StiReport.GetReportFromAssembly("MyReport.dll", true);

VB

Dim Report As StiReport = StiReport.GetReportFromAssembly("MyReport.dll")

你也可以在第一次访问时编译你的报表,接下来就会使用第一次编译后的版本。它的性能将会提高。

C#

string reportName = "MyReport.mrt";
string reportDllName = "MyReport.dll";
StiReport report = null;
// 如果dll文件不存在
if (!File.Exists(reportDllName))
{
// 加载报表定义
report = new StiReport();
report.Load(reportName);
// 编译报表,保存报表的dll版本
report.Compile(reportDllName);
}
else // 如果报表汇编可用
{
// 使用报表汇编
report = StiReport.GetReportFromAssembly(reportDllName);
}

VB

Dim ReportName As String = "MyReport.mrt"
Dim ReportDllName As String = "MyReport.dll"
Dim Report As StiReport = Nothing
'如果dll文件不存在
If Not File.Exists(ReportDllName) Then
'加载报表定义
Report = New StiReport
Report.Load(ReportName)
'编译报表,保存报表的dll版本
Report.Compile(ReportDllName)
Else
'如果报表汇编可用
Report = StiReport.GetReportFromAssembly(ReportName)
End If

4.怎么使报表生成器和编译报表的版本兼容?

兼容性可通过以下两种方式解决:
I.在配置中写入bindingRedirects。示例:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Stimulsoft.Report" publicKeyToken="EBE6666CBA19647A"
culture="neutral" />
<bindingRedirect oldVersion="1.30.0.0" newVersion="1.31.0.0/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Stimulsoft.Report.Export.HtmlExport"
publicKeyToken="EBE6666CBA19647A" culture="neutral" />
<bindingRedirect oldVersion="1.30.0.0" newVersion="1.31.0.0"/>
</dependentAssembly>
[... and etc. for each new assembly ...]
</assemblyBinding>
</runtime>
</configuration>

II.为每一个旧版本创建一个policy发布文件。示例:

policy.1.23.Stimulsoft.Base.dll
policy.1.30.Stimulsoft.Base.dll
policy.1.23.Stimulsoft.Report.dll
policy.1.30.Stimulsoft.Report.dll

5.怎么从汇编加载报表?

可以使用StiReport类的GetReportFromAssembly静态方法实现。此方法返回创建的报告。下面是调用该方法的示例:

C#

//从汇编加载报表
StiReport report = StiReport.GetReportFromAssembly(assembly);
//从文件加载报表
StiReport report = StiReport.GetReportFromAssembly("MyReport.dll");
//从流加载报表
StiReport report = StiReport.GetReportFromAssembly(stream);

VB

'从汇编加载报表
Dim Report As StiReport = StiReport.GetReportFromAssembly(assembly)
'从文件加载报表
Dim Report As StiReport = StiReport.GetReportFromAssembly("MyReport.dll")
'从流加载报表
Dim Report As StiReport = StiReport.GetReportFromAssembly(stream)

购买最新正版授权!"咨询在线客服"

慧都年终盛典火爆开启,一年仅一次的最强促销,破冰钜惠不容错过!!优惠详情点击查看>>


在线
客服
微信
QQ 电话
023-68661681
返回
顶部