在 Telerik Report Designer 中,我在尝试找出正确的 scope 名称来获取每个数据项处理的给定表达式的总和直到每页结束时遇到了最糟糕的时间。
为了简单起见,我的数据源只有 1 列:saleAmount。
适合第 1 页的示例值
第 1 页的页脚运行总和:450
适合第 2 页的剩余值20
500 我还需要在每页的开头(从第二页开始)显示直到上一页结束时处理的累积总和。
根据这篇Telerik Reporting文章
,看来我应该使用RunningValue(scope, Sum(Fields.saleAmount))
虽然RunningValue 函数在详细信息部分和组页脚部分运行良好,显示直到该组结束时的累计总和,但在以下情况下它无法按预期工作:
在
页脚部分我正在寻求一种基于标准 Telerik Report 功能的解决方案,我的意思是,无需实现自定义类即可实现结果。
这是我的示例报告定义(.trdx
),可加载到Telerik Report Designer
<?xml version="1.0" encoding="utf-8"?>
<Report DataSourceName="csvDataSource1" Width="17cm" Name="MyPageRunningTotalSampleReport" xmlns="http://schemas.telerik.com/reporting/2021/2.0">
<DataSources>
<CsvDataSource RecordSeparators="
" FieldSeparators="," Name="csvDataSource1">
<Source>
<String>QSwxMDANCkEsMjAwDQpCLDE1MA0KQiwyMA0KQywzMA==</String>
</Source>
<Columns>
<DataColumn Name="category" />
<DataColumn Name="amount" Type="Decimal" />
</Columns>
</CsvDataSource>
</DataSources>
<Items>
<PageHeaderSection Height="0.8cm" Name="pageHeaderSection1">
<Style>
<BorderStyle Default="Solid" />
</Style>
<Items>
<TextBox Width="3cm" Height="0.6cm" Left="14cm" Top="0.2cm" Value="RunningSum" Name="textBox6">
<Style TextAlign="Right" VerticalAlign="Middle">
<Font Bold="True" />
</Style>
</TextBox>
<TextBox Width="2.7cm" Height="0.6cm" Left="0cm" Top="0.2cm" Value="pageHeader" Name="textBox12">
<Style TextAlign="Left" VerticalAlign="Middle">
<Font Bold="True" />
</Style>
</TextBox>
<TextBox Width="3cm" Height="0.6cm" Left="10.8cm" Top="0.2cm" Value="Amount" Name="textBox4">
<Style TextAlign="Right" VerticalAlign="Middle">
<Font Bold="True" />
</Style>
</TextBox>
</Items>
</PageHeaderSection>
<DetailSection Height="0.6cm" Name="detailSection1">
<Items>
<TextBox Width="3cm" Height="0.6cm" Left="10.8cm" Top="0cm" Value="= Fields.amount" Name="textBox1">
<Style TextAlign="Right" VerticalAlign="Middle" />
</TextBox>
<TextBox Width="3cm" Height="0.6cm" Left="14cm" Top="0cm" Value="= RunningValue("MyPageRunningTotalSampleReport", sum(Fields.amount))" Name="textBox5">
<Style TextAlign="Right" VerticalAlign="Middle" />
</TextBox>
<TextBox Width="2.7cm" Height="0.6cm" Left="0cm" Top="0cm" Value="detailSection1" Name="textBox13">
<Style TextAlign="Justify" VerticalAlign="Middle">
<Font Bold="True" />
</Style>
</TextBox>
</Items>
</DetailSection>
<PageFooterSection Height="8.1cm" Name="pageFooterSection1">
<Style>
<BorderStyle Default="Solid" Top="Solid" Bottom="Solid" Left="Solid" Right="Solid" />
</Style>
<Items>
<TextBox Width="3cm" Height="0.6cm" Left="14cm" Top="1.1cm" Value="= RunningValue("missingScope", sum(Fields.amount))" Name="textBox2">
<Style Color="Red" TextAlign="Right" VerticalAlign="Top">
<Font Size="14pt" Bold="True" />
</Style>
</TextBox>
<TextBox Width="3cm" Height="0.6cm" Left="14cm" Top="2.5cm" Value="= Exec("MyPageRunningTotalSampleReport", sum(Fields.amount))" Name="textBox3">
<Style TextAlign="Right" VerticalAlign="Middle">
<Font Size="14pt" Bold="True" />
</Style>
</TextBox>
<TextBox Width="2.7cm" Height="0.6cm" Left="0cm" Top="0cm" Value="pageFooter" Name="textBox14">
<Style TextAlign="Left" VerticalAlign="Middle">
<Font Bold="True" />
</Style>
</TextBox>
<TextBox Width="4.2cm" Height="0.6cm" Left="9.6cm" Top="2.5cm" Value="Sum until end of report" Name="textBox15">
<Style TextAlign="Right" VerticalAlign="Middle">
<Font Bold="False" />
</Style>
</TextBox>
<HtmlTextBox Width="11.4cm" Height="1.1cm" Left="2.4cm" Top="1.1cm" Value="<span style="font-size: 9pt">Running total since the begining of first page until the end of page <strong>{PageNumber}</strong></span>" Name="htmlTextBox2">
<Style TextAlign="Right" />
</HtmlTextBox>
<TextBox Width="3cm" Height="0.6cm" Left="14cm" Top="0.103cm" Value="= PageExec('detailSection1', sum(Fields.amount))" Name="textBox9">
<Style TextAlign="Right" VerticalAlign="Middle">
<Font Size="14pt" Bold="True" />
</Style>
</TextBox>
<HtmlTextBox Width="10.7cm" Height="0.6cm" Left="3.1cm" Top="0.103cm" Value="Total of all detail items shown on page <strong>{PageNumber}</strong>" Name="htmlTextBox3">
<Style TextAlign="Right" VerticalAlign="Middle" />
</HtmlTextBox>
</Items>
</PageFooterSection>
</Items>
<PageSettings PaperKind="A6" Landscape="True" ContinuousPaper="False">
<Margins>
<MarginsU Left="2cm" Right="2cm" Top="2cm" Bottom="2cm" />
</Margins>
</PageSettings>
<StyleSheet>
<StyleRule>
<Style>
<Padding Left="2pt" Right="2pt" />
</Style>
<Selectors>
<TypeSelector Type="TextItemBase" />
<TypeSelector Type="HtmlTextBox" />
</Selectors>
</StyleRule>
</StyleSheet>
</Report>
<Code>
<![CDATA[
Dim pageRunningSum As Decimal = 0
Public Function UpdatePageRunningSum(amount As Decimal) As Decimal
pageRunningSum += amount
Return pageRunningSum
End Function
]]>
</Code>
现在,每当您处理报告中的金额时,此代码都会在后台更新运行总和。接下来,让我们在报告中使用此后台代码。在 PageHeaderSection 中,我们将确保每次遇到新金额时都会更新运行总和。
= Code.UpdatePageRunningSum(Fields.amount)
在 PageFooterSection 中,您也执行相同的操作。这样,将根据每个页面处理的金额计算运行总和。
= Code.UpdatePageRunningSum(Fields.amount)
通过这些更改,您的报告现在应该在页眉和页脚部分正确显示运行总和。
自定义代码可能需要绿灯才能运行,因此请仔细检查您的报告查看器设置以确保允许它执行其操作。