报表是每个做信息系统产品人员都应该关注的一部分,在WPF下很多人使用FlowDocuments来生成报表,这个虽然不错,但是对于复杂的报表来说还是需要一个报表引擎。
“This project allows you to create reports using WPF (WindowsPresentation Foundation). Its supports headers and footers, DataTablebinding, barcode generation, XPS creation and more.”
它是现在WPF版本下的一个报表引擎,目前版本还比较低(,但是可以作为以后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\" ); |
Here is how our template looks
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" /> |
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" > |
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" /> |
027 | < Style x:Key = "dataRowStyle" TargetType = "{x:Type TableRowGroup}" > |
028 | < Setter Property = "FontSize" Value = "12" /> |
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" /> |
040 | < TableColumn Width = "0.5*" /> |
041 | < TableColumn Width = "2*" /> |
042 | < TableColumn Width = "*" /> |
043 | < TableColumn Width = "0.5*" /> |
045 | < TableRowGroup Style = '{StaticResource headerFooterRowStyle}' > |
048 | < Paragraph TextAlignment = 'Center' > |
053 | < Paragraph TextAlignment = 'Center' > |
054 | < Bold >Item Name</ Bold > |
058 | < Paragraph TextAlignment = 'Center' > |
063 | < Paragraph TextAlignment = 'Center' > |
069 | < TableRowGroup Style = '{StaticResource dataRowStyle}' > |
070 | < xrd:TableRowForDataTable TableName = 'Ean' > |
073 | < xrd:InlineTableCellValue PropertyName = 'Position' /> |
078 | < xrd:InlineTableCellValue PropertyName = 'Item' /> |
083 | < xrd:InlineTableCellValue PropertyName = 'EAN' /> |
087 | < Paragraph TextAlignment = 'Center' > |
088 | < xrd:InlineTableCellValue PropertyName = 'Count' AggregateGroup = 'ItemCount' /> |
091 | </ xrd:TableRowForDataTable > |
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. |
099 | </ xrd:SectionDataGroup > |
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