使用C1PrintDocument控件 > 表达式,脚本,标签 > 文本表达式对ID的访问 |
如上面提到的,括号内的表达式可以在RenderText以及ParagraphText对象的Text属性中使用。
这个变量的引用生成的文档。这可以用在许多方面,例如,下面的代码将打印当前文档的作者:
Visual Basic
Visual Basic |
拷贝代码
|
---|---|
Dim doc As New C1PrintDocument() Dim rt As New RenderText("Landscape is " + _ "[Iif(Page.PageSettings.Landscape,\"TRUE\",\"FALSE\")].") doc.Body.Children.Add(rt) |
C#
C# |
拷贝代码
|
---|---|
C1PrintDocument doc = new C1PrintDocument(); RenderText rt = new RenderText("Landscape is " + "[Iif(Page.PageSettings.Landscape,\"TRUE\",\"FALSE\")]."); doc.Body.Children.Add(rt); |
这个变量引用当前的render对象。例如,下面的代码将打印当前render对象的名称:
Visual Basic
Visual Basic |
拷贝代码
|
---|---|
Dim doc As New C1PrintDocument() Dim rt As New RenderText( _ "The object's name is [RenderObject.Name]") rt.Name = "MyRenderText" doc.Body.Children.Add(rt) |
C#
C# |
拷贝代码
|
---|---|
C1PrintDocument doc = new C1PrintDocument(); RenderText rt = new RenderText( "The object's name is [RenderObject.Name]"); rt.Name = "MyRenderText"; doc.Body.Children.Add(rt); |
这个变量引用当前页面(C1Page类型的对象)。而脚本中最常使用的关于页面对象的成员则可以直接访问(参见下面的PageNo,PageCount等属性),其他数据则可以通过Page变量进行访问,比如当前页面的设置。例如,下面的代码将在当前页面布局是水平方向打印时打印“Landscape is TRUE”,否则将打印“Landscape is FALSE”:
Visual Basic
Visual Basic |
拷贝代码
|
---|---|
Dim doc As New C1PrintDocument() Dim rt As New RenderText("Landscape is " + _ "[Iif(Page.PageSettings.Landscape,\"TRUE\",\"FALSE\")].") doc.Body.Children.Add(rt) |
C#
C# |
拷贝代码
|
---|---|
C1PrintDocument doc = new C1PrintDocument(); RenderText rt = new RenderText("Landscape is " + "[Iif(Page.PageSettings.Landscape,\"TRUE\",\"FALSE\")]."); doc.Body.Children.Add(rt); |
此名称解析为从1开始计数的页码。相当于 Page.PageNo。
此名称解析为文档的总页数。相当于Page.PageCount。例如,下面的代码可以用于产生通用的“第X页,共Y页”的页眉:
Visual Basic
Visual Basic |
拷贝代码
|
---|---|
Dim doc As New C1PrintDocument() doc.PageLayout.PageHeader = New RenderText( _ "Page [PageNo] of [PageCount]") |
C#
C# |
拷贝代码
|
---|---|
C1PrintDocument doc = new C1PrintDocument(); doc.PageLayout.PageHeader = new RenderText( "Page [PageNo] of [PageCount]"); |
此名称解析为当前水平方向上的从1开始计算的页码。(对于没有水平分页符的文档,将返回1。)
此名称解析为当前垂直方向上的页码。(对于没有水平分页符的文档,则和PageNo相同。)
此名称解析为文档水平方向的分页总数。(对于没有水平分页符的文档,将始终返回1。)
此名称解析为文档的总页数。(对于没有水平分页符的文档,则和PageCount相等。)
需要着重注意的是,这里提到的任何和页面编码相关的值可以用在文档的任何地方,不一定必须放在页眉或页脚上。
该变量引用数据库所有可用字段的集合,类型为C1.C1Preview.DataBinding.FieldCollection。它只能用于数据绑定的文档。例如,下面的代码将打印NWIND数据库Products数据表的产品名称列表。
Visual Basic
Visual Basic |
拷贝代码
|
---|---|
Dim doc As New C1PrintDocument() Dim dSrc As New DataSource() dSrc.ConnectionProperties.DataProvider = DataProviderEnum.OLEDB dSrc.ConnectionProperties.ConnectString = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND.MDB" Dim dSet1 As New C1.C1Preview.DataBinding.DataSet( _ dSrc, "select * from Products") doc.DataSchema.DataSources.Add(dSrc) doc.DataSchema.DataSets.Add(dSet1) Dim rt As New RenderText() rt.DataBinding.DataSource = dSet1 rt.Text = "[Fields!ProductName.Value]" doc.Body.Children.Add(rt) |
C#
C# |
拷贝代码
|
---|---|
C1PrintDocument doc = new C1PrintDocument(); DataSource dSrc = new DataSource(); dSrc.ConnectionProperties.DataProvider = DataProviderEnum.OLEDB; dSrc.ConnectionProperties.ConnectString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND.MDB"; C1.C1Preview.DataBinding.DataSet dSet1 = new C1.C1Preview.DataBinding.DataSet(dSrc, "select * from Products"); doc.DataSchema.DataSources.Add(dSrc); doc.DataSchema.DataSets.Add(dSet1); RenderText rt = new RenderText(); doc.Body.Children.Add(rt); rt.DataBinding.DataSource = dSet1; rt.Text = "[Fields!ProductName.Value]"; |
请注意在最后一行是如何通过“!”访问字段数组的元素。或者,你可以写:
Visual Basic
Visual Basic |
拷贝代码
|
---|---|
rt.Text = "[Fields(\"ProductName\").Value]" |
C#
C# |
拷贝代码
|
---|---|
rt.Text = "[Fields(\"ProductName\").Value]"; |
但使用“!”符号更短更容易阅读。
这个变量来访问的文档中定义的汇总的集合。集合的类型为C1.C1Preview.DataBinding.AggregateCollection,其中的元素类型为C1.C1Preview.DataBinding.Aggregate。例如,下面的代码将在产品的列表后打印平均单价:
Visual Basic
Visual Basic |
拷贝代码
|
---|---|
Dim doc As New C1PrintDocument() Dim dSrc As New DataSource() dSrc.ConnectionProperties.DataProvider = DataProviderEnum.OLEDB dSrc.ConnectionProperties.ConnectString = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND.MDB" C1.C1Preview.DataBinding.DataSet dSet1 = _ new C1.C1Preview.DataBinding.DataSet(dSrc, _ "select * from Products") doc.DataSchema.DataSources.Add(dSrc) doc.DataSchema.DataSets.Add(dSet1) Dim rt As New RenderText() doc.Body.Children.Add(rt) rt.DataBinding.DataSource = dSet1 rt.Text = "[Fields!ProductName.Value]" doc.DataSchema.Aggregates.Add(new Aggregate( _ "AveragePrice", "Fields!UnitPrice.Value", _ rt.DataBinding, RunningEnum.Document, _ AggregateFuncEnum.Average)) doc.Body.Children.Add(new RenderText( _ "Average price: [Aggregates!AveragePrice.Value]")) |
C#
C# |
拷贝代码
|
---|---|
C1PrintDocument doc = new C1PrintDocument(); DataSource dSrc = new DataSource(); dSrc.ConnectionProperties.DataProvider = DataProviderEnum.OLEDB; dSrc.ConnectionProperties.ConnectString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND.MDB"; C1.C1Preview.DataBinding.DataSet dSet1 = new C1.C1Preview.DataBinding.DataSet(dSrc, "select * from Products"); doc.DataSchema.DataSources.Add(dSrc); doc.DataSchema.DataSets.Add(dSet1); RenderText rt = new RenderText(); doc.Body.Children.Add(rt); rt.DataBinding.DataSource = dSet1; rt.Text = "[Fields!ProductName.Value]"; doc.DataSchema.Aggregates.Add(new Aggregate( "AveragePrice", "Fields!UnitPrice.Value", rt.DataBinding, RunningEnum.Document, AggregateFuncEnum.Average)); doc.Body.Children.Add(new RenderText( "Average price: [Aggregates!AveragePrice.Value]")); |
该变量允许访问当前render对象的DataBinding属性,类型为C1.C1Preview.DataBinding.C1DataBinding。例如,下面的代码(从展示Fileds变量用法的示例修改而来)将通过使用render对象的DataBinding属性的RowNumber成员在文本表达式中生成一个带有编码的列表:
Visual Basic
Visual Basic |
拷贝代码
|
---|---|
Dim doc As New C1PrintDocument() Dim dSrc As New DataSource() dSrc.ConnectionProperties.DataProvider = DataProviderEnum.OLEDB dSrc.ConnectionProperties.ConnectString = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND.MDB" C1.C1Preview.DataBinding.DataSet dSet1 = _ new C1.C1Preview.DataBinding.DataSet(dSrc, _ "select * from Products") doc.DataSchema.DataSources.Add(dSrc) doc.DataSchema.DataSets.Add(dSet1) Dim rt As New RenderText() rt.DataBinding.DataSource = dSet1 rt.Text = "[DataBinding.RowNumber]: [Fields!ProductName.Value]" doc.Body.Children.Add(rt) |
C#
C# |
拷贝代码
|
---|---|
C1PrintDocument doc = new C1PrintDocument(); DataSource dSrc = new DataSource(); dSrc.ConnectionProperties.DataProvider = DataProviderEnum.OLEDB; dSrc.ConnectionProperties.ConnectString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND.MDB"; C1.C1Preview.DataBinding.DataSet dSet1 = new C1.C1Preview.DataBinding.DataSet(dSrc, "select * from Products"); doc.DataSchema.DataSources.Add(dSrc); doc.DataSchema.DataSets.Add(dSet1); RenderText rt = new RenderText(); rt.DataBinding.DataSource = dSet1; rt.Text = "[DataBinding.RowNumber]: [Fields!ProductName.Value]"; doc.Body.Children.Add(rt); |