如何在 Telerik Reporting 中计算页眉和页脚运行值

问题描述 投票:0回答:1

Telerik Report Designer 中,我在尝试找出正确的 scope 名称来获取每个数据项处理的给定表达式的总和直到每页结束时遇到了最糟糕的时间。

为了简单起见,我的数据源只有 1 列:saleAmount

适合第 1 页的示例值

  • 100
  • 200
  • 150

第 1 页的页脚运行总和:450

适合第 2 页的剩余值

20
  • 30
  • 第 2 页
的页脚运行总和:

500 我还需要在每页的开头(从第二页开始)显示直到上一页结束时处理的累积总和。

根据这篇

Telerik Reporting文章

,看来我应该使用

RunningValue(scope, Sum(Fields.saleAmount))

虽然 
RunningValue

函数在详细信息部分和组页脚部分运行良好,显示直到该组结束时的累计总和,但在以下情况下它无法按预期工作:

页脚部分
    ,它不是显示从第一个数据源项目到当前页面上处理的最后一个项目的总和,而是显示数据源中包含的所有记录的总和,这似乎是一个主要缺陷;
  • 页面标题部分
  • ,它不是显示从第一个数据源项到上一页处理的最后一项的总和,而是显示数据源中包含的所有记录的总和,这似乎也是一个主要缺陷;
  • 我已经花了很多时间试图弄清楚我到底应该使用什么作为
  • scope
参数。

我正在寻求一种基于标准 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="&#xD;&#xA;" 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(&quot;MyPageRunningTotalSampleReport&quot;, 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(&quot;missingScope&quot;, 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(&quot;MyPageRunningTotalSampleReport&quot;, 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="&lt;span style=&quot;font-size: 9pt&quot;&gt;Running total since the begining of first page until the end of page &lt;strong&gt;{PageNumber}&lt;/strong&gt;&lt;/span&gt;" 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 &lt;strong&gt;{PageNumber}&lt;/strong&gt;" 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>

那么,您正在使用 Telerik Report Designer,尝试在页眉和页脚中获取这些运行总和,对吧?看起来 Telerik 并没有让它变得非常容易开箱即用,但我们可以添加一些自定义代码来使其工作。
telerik telerik-reporting
1个回答
0
投票
首先,您可以为一些特殊代码创建一个空间。当我们检查您的数据时,我们将使用它来跟踪运行总和。

<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)

通过这些更改,您的报告现在应该在页眉和页脚部分正确显示运行总和。

自定义代码可能需要绿灯才能运行,因此请仔细检查您的报告查看器设置以确保允许它执行其操作。

© www.soinside.com 2019 - 2024. All rights reserved.