翻譯|使用教程|編輯:李顯亮|2021-09-17 11:00:00.977|閱讀 162 次
概述:此示例說明如何使用代碼中的 Business Objects 集合創(chuàng)建報(bào)告。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Stimulsoft Ultimate是用于創(chuàng)建報(bào)表和儀表板的通用工具集。該產(chǎn)品包括用于WinForms、ASP.NET、.NET Core、JavaScript、WPF、PHP、Java和其他環(huán)境的完整工具集。
Stimulsoft Reports不僅擁有強(qiáng)大的報(bào)表導(dǎo)出系統(tǒng),而且還支持多種報(bào)表導(dǎo)出格式,擁有簡單且強(qiáng)大的報(bào)表引擎。Stimulsoft Reports基本原則是,用簡單常規(guī)的方法創(chuàng)建報(bào)表,將不同的技術(shù)應(yīng)用于應(yīng)用程序。Stimulsoft Reports ..NET一個(gè)基于.NET框架的報(bào)表生成器,能夠幫助你創(chuàng)建結(jié)構(gòu)、功能豐富的報(bào)表。不僅界面友好,而且使用便捷,能夠讓你輕松創(chuàng)建所有報(bào)表。
點(diǎn)擊下載Stimulsoft Reports .NET v2021.3.1最新版
此示例說明如何使用代碼中的 Business Objects 集合創(chuàng)建報(bào)告。Business Objects 是一個(gè)對(duì)象類數(shù)據(jù),數(shù)據(jù)可以用不同的結(jié)構(gòu)呈現(xiàn):表格、列表、數(shù)組等。該FillBusinessObject()方法創(chuàng)建并填充數(shù)據(jù)集合:
private ArrayList list = null; private void FillBusinessObject() { list = new ArrayList(); list.Add(new BusinessEntity("name1", "alias1")); list.Add(new BusinessEntity("name2", "alias2")); list.Add(new BusinessEntity("name3", "alias3")); }
數(shù)據(jù)已創(chuàng)建,現(xiàn)在您需要顯示它。首先,您應(yīng)該在字典中創(chuàng)建一個(gè)新的報(bào)表和數(shù)據(jù)結(jié)構(gòu),將數(shù)據(jù)從 Business Object 傳輸?shù)阶值洌?/span>
private void PrintDataGrid(DataGrid sender) { StiReport report = new StiReport(); report.ScriptLanguage = StiReportLanguageType.CSharp; // Add data to datastore report.RegData("MyList", list); // Fill dictionary report.Dictionary.Synchronize(); StiPage page = report.Pages.Items[0]; ...
然后您需要將組件添加到報(bào)告模板中。您應(yīng)該創(chuàng)建帶 Header、Data 和 Footer。這些帶用于放置帶有文本或?qū)I(yè)務(wù)對(duì)象字段的引用的文本框:
... // Create HeaderBand StiHeaderBand headerBand = new StiHeaderBand(); headerBand.Name = "HeaderBand"; page.Components.Add(headerBand); // Create Databand StiDataBand dataBand = new StiDataBand(); dataBand.DataSourceName = "MyList"; dataBand.Height = 0.5f; dataBand.Name = "DataBand"; page.Components.Add(dataBand); StiDataSource dataSource = report.Dictionary.DataSources[0]; // Create texts Double pos = 0; Double columnWidth = StiAlignValue.AlignToMinGrid(page.Width / dataSource.Columns.Count, 0.1, true); int nameIndex = 1; foreach (StiDataColumn column in dataSource.Columns) { if (column.Name == "_ID" || column.Name == "_Current") continue; // Create text on header StiText headerText = new StiText(new RectangleD(pos, 0, columnWidth, 0.5f)); headerText.Text.Value = column.Name; headerText.HorAlignment = StiTextHorAlignment.Center; headerText.Name = "HeaderText" + nameIndex.ToString(); headerText.Brush = new StiSolidBrush(Color.MediumSeaGreen); headerText.Border.Side = StiBorderSides.All; headerBand.Components.Add(headerText); // Create text on Data Band StiText dataText = new StiText(new RectangleD(pos, 0, columnWidth, 0.5f)); dataText.Text.Value = "{MyList." + column.Name + "}"; dataText.Name = "DataText" + nameIndex.ToString(); dataText.Border.Side = StiBorderSides.All; dataBand.Components.Add(dataText); pos += columnWidth; nameIndex ++; } // Create FooterBand StiFooterBand footerBand = new StiFooterBand(); footerBand.Height = 0.5f; footerBand.Name = "FooterBand"; page.Components.Add(footerBand); // Create text on footer StiText footerText = new StiText(new RectangleD(0, 0, page.Width, 0.5f)); footerText.Text.Value = "Count - {Count()}"; footerText.HorAlignment = StiTextHorAlignment.Right; footerText.Name = "FooterText"; footerText.Brush = new StiSolidBrush(Color.LightGreen); footerBand.Components.Add(footerText); ...
在此之后,您可以呈現(xiàn)報(bào)告并將其顯示在查看器中(或調(diào)用報(bào)告設(shè)計(jì)器):
... // Render without progress bar report.Render(false); report.Show(); // For checking created report you can uncomment this line //report.Design(); }
在下面的屏幕截圖中,您可以看到示例代碼的結(jié)果:
Aspose、E-iceblue、FastReport、Stimulsoft等文檔/報(bào)表圖表類開發(fā)工具享超低折扣,如有需要可直接。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn