开源 - 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

1 ReportDocument reportDocument = new ReportDocument();

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

1 StreamReader reader = new StreamReader(new FileStream(@"Templates\SimpleReport.xaml", FileMode.Open, FileAccess.Read));
2 reportDocument.XamlData = reader.ReadToEnd();
3 reportDocument.XamlImagePath = Path.Combine(Environment.CurrentDirectory, @"Templates\");
4 reader.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…

1 ReportData data = new ReportData();

First add some “metadata”

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

And then the DataTables

1 data.DataTables.Add(table);

Here, table is of type DataTable.

And that is it!

Finally export it to Xps and show

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

You can use the standard DocumentViewer to display the report

Read more

posted on 2009-12-19 10:22  周 金根  阅读(14073)  评论(10编辑  收藏  举报

导航