开源 - WPF报表引擎

  报表是每个做信息系统产品人员都应该关注的一部分,在WPF下很多人使用FlowDocuments来生成报表,这个虽然不错,但是对于复杂的报表来说还是需要一个报表引擎。

Open-Source .NET WPF Reporting Engine

 “This project allows you to create reports using WPF (WindowsPresentation Foundation). Its supports headers and footers, DataTablebinding, barcode generation, XPS creation and more.”

  它是现在WPF版本下的一个报表引擎,目前版本还比较低(v0.5 alpha),但是可以作为以后OpenExpressAppWPF版本报表的预览控件的参考。

  下面放上几张它例子的图,感兴趣的也可以去看看。

使用

Open-Source WPF Reporting Engine

FlowDocuments

  最开始说过有人使用FlowDocuments来做报表,以下为一个例子,想使用这个来作报表的可以参考。

 

 报表引擎设计.pdf

推荐:你可能需要的在线电子书

敏捷个人sina围裙:http://q.t.sina.com.cn/135484

欢迎转载,转载请注明:转载自敏捷个人网站

First things, first… Create a ReportDocument. This is the “container" for our report

1ReportDocument reportDocument = new ReportDocument();

Next, we need to supply a template for our report. 

1StreamReader reader = new StreamReader(new FileStream(@"Templates\SimpleReport.xaml", FileMode.Open, FileAccess.Read));
2reportDocument.XamlData = reader.ReadToEnd();
3reportDocument.XamlImagePath = Path.Combine(Environment.CurrentDirectory, @"Templates\");
4reader.Close();

Here is how our template looks

002              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
003              xmlns:xrd="clr-namespace:CodeReason.Reports.Document;assembly=CodeReason.Reports"
004              PageHeight="29.7cm" PageWidth="21cm" ColumnWidth="21cm">
005    <xrd:ReportProperties>
006        <xrd:ReportProperties.ReportName>SimpleReport</xrd:ReportProperties.ReportName>
007        <xrd:ReportProperties.ReportTitle>Simple Report</xrd:ReportProperties.ReportTitle>
008    </xrd:ReportProperties>
009    <Section Padding="80,10,40,10" FontSize="12">
010        <Paragraph FontSize="24" FontWeight="Bold">
011            <xrd:InlineContextValue PropertyName="ReportTitle" />
012        </Paragraph>
013        <Paragraph>This is a simple report example that contains a table.
014            The table is filled using a DataTable object.</Paragraph>
015        <xrd:SectionDataGroup DataGroupName="ItemList">
016            <Paragraph FontSize="20" FontWeight="Bold">Item List</Paragraph>
017            <Table CellSpacing="0" BorderBrush="Black" BorderThickness="0.02cm">
018                <Table.Resources>
019                    <!-- Style for header/footer rows. -->
020                    <Style x:Key="headerFooterRowStyle" TargetType="{x:Type TableRowGroup}">
021                        <Setter Property="FontWeight" Value="DemiBold"/>
022                        <Setter Property="FontSize" Value="16"/>
023                        <Setter Property="Background" Value="LightGray"/>
024                    </Style>
025 
026                    <!-- Style for data rows. -->
027                    <Style x:Key="dataRowStyle" TargetType="{x:Type TableRowGroup}">
028                        <Setter Property="FontSize" Value="12"/>
029                    </Style>
030 
031                    <!-- Style for data cells. -->
032                    <Style TargetType="{x:Type TableCell}">
033                        <Setter Property="Padding" Value="0.1cm"/>
034                        <Setter Property="BorderBrush" Value="Black"/>
035                        <Setter Property="BorderThickness" Value="0.01cm"/>
036                    </Style>
037                </Table.Resources>
038 
039                <Table.Columns>
040                    <TableColumn Width="0.5*" />
041                    <TableColumn Width="2*" />
042                    <TableColumn Width="*" />
043                    <TableColumn Width="0.5*" />
044                </Table.Columns>
045                <TableRowGroup Style='{StaticResource headerFooterRowStyle}'>
046                    <TableRow>
047                        <TableCell>
048                            <Paragraph TextAlignment='Center'>
049                                <Bold>Pos.</Bold>
050                            </Paragraph>
051                        </TableCell>
052                        <TableCell>
053                            <Paragraph TextAlignment='Center'>
054                                <Bold>Item Name</Bold>
055                            </Paragraph>
056                        </TableCell>
057                        <TableCell>
058                            <Paragraph TextAlignment='Center'>
059                                <Bold>EAN</Bold>
060                            </Paragraph>
061                        </TableCell>
062                        <TableCell>
063                            <Paragraph TextAlignment='Center'>
064                                <Bold>Count</Bold>
065                            </Paragraph>
066                        </TableCell>
067                    </TableRow>
068                </TableRowGroup>
069                <TableRowGroup Style='{StaticResource dataRowStyle}'>
070                    <xrd:TableRowForDataTable TableName='Ean'>
071                        <TableCell>
072                            <Paragraph>
073                                <xrd:InlineTableCellValue PropertyName='Position' />
074                            </Paragraph>
075                        </TableCell>
076                        <TableCell>
077                            <Paragraph>
078                                <xrd:InlineTableCellValue PropertyName='Item' />
079                            </Paragraph>
080                        </TableCell>
081                        <TableCell>
082                            <Paragraph>
083                                <xrd:InlineTableCellValue PropertyName='EAN'/>
084                            </Paragraph>
085                        </TableCell>
086                        <TableCell>
087                            <Paragraph TextAlignment='Center'>
088                                <xrd:InlineTableCellValue PropertyName='Count' AggregateGroup='ItemCount'/>
089                            </Paragraph>
090                        </TableCell>
091                    </xrd:TableRowForDataTable>
092                </TableRowGroup>
093            </Table>
094            <Paragraph>
095                There are
096                <xrd:InlineAggregateValue AggregateGroup='ItemCount' AggregateValueType='Count' EmptyValue='no' FontWeight='Bold' /> item positions with a total of
097                <xrd:InlineAggregateValue AggregateGroup='ItemCount' AggregateValueType='Sum' EmptyValue='0' FontWeight='Bold' /> items listed.
098            </Paragraph>
099        </xrd:SectionDataGroup>
100    </Section>
101</FlowDocument>

I will go into more detail on how to customize this template in future posts. Now the data…

1ReportData data = new ReportData();

First add some “metadata”

1data.ReportDocumentValues.Add("PrintDate", DateTime.Now);

And then the DataTables

1data.DataTables.Add(table);

Here, table is of type DataTable.

And that is it!

Finally export it to Xps and show

1XpsDocument xps = reportDocument.CreateXpsDocument(<strong>data</strong>);

You can use the standard DocumentViewer to display the report

Read more

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值