翻譯|使用教程|編輯:王香|2018-09-21 15:17:41.000|閱讀 427 次
概述:本文主要介紹Stimulsoft報(bào)表中顯示了在運(yùn)行時(shí)創(chuàng)建報(bào)表的可能性。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
【下載Stimulsoft Reports.WPF最新版本】
此示例項(xiàng)目顯示了在運(yùn)行時(shí)創(chuàng)建報(bào)表的可能性。使用代碼創(chuàng)建報(bào)表后,可以在WPF查看器中顯示它。首先,初始化組件并加載未來報(bào)表的數(shù)據(jù):
private System.Data.DataSet dataSet1 = new System.Data.DataSet(); public Window1() { StiOptions.Wpf.CurrentTheme = StiOptions.Wpf.Themes.Office2013Theme; Stimulsoft.Report.Wpf.StiThemesHelper.LoadTheme(this); InitializeComponent(); dataSet1.ReadXmlSchema("..\\..\\Data\\Demo.xsd"); dataSet1.ReadXml("..\\..\\Data\\Demo.xml"); dataSet1.DataSetName = "Demo"; }
所有必要的操作都可以在應(yīng)用程序的Button_Click 事件中完成。首先,創(chuàng)建新的報(bào)表對(duì)象,注冊(cè)數(shù)據(jù)并將其與報(bào)表dictionary同步:
private void Button_Click(object sender, RoutedEventArgs e) { StiReport report = new StiReport(); //Add data to datastore report.RegData(dataSet1); //Fill dictionary report.Dictionary.Synchronize(); ...
然后我們需要?jiǎng)?chuàng)建報(bào)表組件。首先,使用將顯示標(biāo)題的Text組件將Header Band添加到報(bào)表頁面:
... StiPage page = report.Pages[0]; //Create HeaderBand StiHeaderBand headerBand = new StiHeaderBand(); headerBand.Height = 0.5; headerBand.Name = "HeaderBand"; page.Components.Add(headerBand); //Create text on header StiText headerText = new StiText(new RectangleD(0, 0, 5, 0.5)); headerText.Text = "CompanyName"; headerText.HorAlignment = StiTextHorAlignment.Center; headerText.Name = "HeaderText"; headerText.Brush = new StiSolidBrush(System.Drawing.Color.LightGreen); headerBand.Components.Add(headerText); ...
接下來,使用添加表達(dá)式的Text組件添加數(shù)據(jù)帶。此表達(dá)式組合了客戶數(shù)據(jù)源中的行號(hào)和CompanyName數(shù)據(jù)列:
... //Create Databand StiDataBand dataBand = new StiDataBand(); dataBand.DataSourceName = "Customers"; dataBand.Height = 0.5; dataBand.Name = "DataBand"; page.Components.Add(dataBand); //Create text StiText dataText = new StiText(new RectangleD(0, 0, 5, 0.5)); dataText.Text = "{Line}.{Customers.CompanyName}"; dataText.Name = "DataText"; dataBand.Components.Add(dataText); ...
最后,使用Text組件添加頁腳頁帶,該組件在頁面底部顯示文本。最后一個(gè)操作是WPF查看器的調(diào)用,它將自動(dòng)構(gòu)建和顯示報(bào)表:
... //Create FooterBand StiFooterBand footerBand = new StiFooterBand(); footerBand.Height = 0.5; footerBand.Name = "FooterBand"; page.Components.Add(footerBand); //Create text on footer StiText footerText = new StiText(new RectangleD(0, 0, 5, 0.5)); footerText.Text = "Count - {Count()}"; footerText.HorAlignment = StiTextHorAlignment.Right; footerText.Name = "FooterText"; footerText.Brush = new StiSolidBrush(System.Drawing.Color.LightGreen); footerBand.Components.Add(footerText); report.ShowWithWpf(); }
示例代碼的結(jié)果如下圖所示:
購買Stimulsoft正版授權(quán),請(qǐng)點(diǎn)擊“”喲!
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn