使用 C1Report 控件 > 高级功能 > 无绑定报表 |
无绑定报表是没有底层数据源的报表记录集。 这种报表类型在以下两种情况下是非常有用的:
举一个简单的无绑定报表的例子,创建一个简单的没有源记录的通讯录。 使用C1ReportDesigner就可以完成该功能,只需要将ConnectionString和RecordSource属性设为空,并在报表中添加占位符。 占位符字段是简单的标签,其内容会通过应用程序来设置。
假如需要创建名称中包含六个占位符的报表如“FldHeadlineXXX”和“FldBodyXXX”(其中XXX为1至3)占位符域,你可以使用下面的代码来渲染报表:
Visual Basic
Visual Basic |
拷贝代码
|
---|---|
Private Sub MakeReport() ' find report definition file Dim path As String = Application.StartupPath Dim i As Integer = path.IndexOf("\bin") If i > -1 Then path = path.Substring(0, i) path = path & "\" ' load unbound report c1r.Load(path & "Newsletter.xml", "NewsLetter") ' set field values c1r.Fields("FldHeadline1").Text = "C1Report Launched" c1r.Fields("FldBody1").Text = "ComponentOne unveils..." c1r.Fields("FldHeadline2").Text = "Competitive Upgrades" c1r.Fields("FldBody2").Text = "Get ahead ..." c1r.Fields("FldHeadline3").Text = "C1Report Designer" c1r.Fields("FldBody3").Text = "The C1Report Designer..." ' done, show the report c1ppv.Document = c1r ' and/or save it to an HTML document so your subscribers ' can get to it over the Web c1r.RenderToFile(path & "Newsletter.htm", FileFormatEnum.HTML) End Sub |
C#
C# |
拷贝代码
|
---|---|
private void MakeReport() { // find report definition file string path = Application.StartupPath; int i = path.IndexOf("\bin"); if ( i > -1 ) { path = path.Substring(0, i) path = path + "\"; // load unbound report c1r.Load(path + "Newsletter.xml", "NewsLetter"); // set field values c1r.Fields["FldHeadline1"].Text = "C1Report Launched"; c1r.Fields["FldBody1"].Text = "ComponentOne unveils..."; c1r.Fields["FldHeadline2"].Text = "Competitive Upgrades"; c1r.Fields["FldBody2"].Text = "get { ahead ..."; c1r.Fields["FldHeadline3"].Text = "C1Report Designer"; c1r.Fields["FldBody3"].Text = "The C1Report Designer..."; // done, show the report c1ppv.Document = c1r; // and/or save it to an HTML document so your subscribers // can get to it over the Web c1r.RenderToFile(path + "Newsletter.htm", FileFormatEnum.HTML); } |
下面是ComponentOne的通讯原型。 注意,我们提供的简单的程序没有处理任何格式问题; 它只是简单的呈现了报表内容。 示例中显示的报表是用C1ReportDesigner应用程序创建的,报表定义时考虑了所有的格式,包括带Logo的标题,页脚,字体和文本定位。
内容和格式分离是无绑定报表的主要优点之一。