報(bào)表生成器FastReport .Net程序員手冊(cè):如何使用代碼創(chuàng)建報(bào)告
FastReport .Net是適用于Windows Forms,ASP.NET,MVC和.NET Core的全功能解決方案。它可以在Microsoft Visual Studio 2005-2019中使用。支持.Net Framework 2.0-4.x,.NET Core 3.0及以上版本。
在FastReport .NET 2021.1的新版本中,我們實(shí)現(xiàn)了對(duì).NET 5的支持。添加了新消息-Deutsce Post Leitcode。將RTF轉(zhuǎn)換為報(bào)告對(duì)象的算法已獲得顯著改進(jìn)。數(shù)字的新功能。歡迎下載體驗(yàn)。(單擊下方按鈕下載)
立即點(diǎn)擊下載FastReport.NET v2021.1最新版
Fastreport.NET在線(xiàn)購(gòu)買(mǎi)價(jià)優(yōu)惠,專(zhuān)享85折起!趕緊加入購(gòu)物清單吧!
使用代碼創(chuàng)建報(bào)告
讓我們考慮如何在代碼中創(chuàng)建一個(gè)報(bào)表。我們將創(chuàng)建以下報(bào)表。
報(bào)告報(bào)告= new Report(); //注冊(cè)“產(chǎn)品”表 report.RegisterData(dataSet1.Tables [“ Products”],“ Products”); //使其可以在報(bào)告中使用 report.GetDataSource(“ Products”)。Enabled = true; //創(chuàng)建所有頁(yè)邊距設(shè)置為1cm的A4頁(yè)面 ReportPage page1 = new ReportPage(); page1.Name =“ Page1”; report.Pages.Add(page1); //創(chuàng)建ReportTitle帶 page1.ReportTitle =新的ReportTitleBand(); page1.ReportTitle.Name =“ ReportTitle1”; //將其高度設(shè)置為1.5cm page1.ReportTitle.Height =單位。厘米* 1.5f; //創(chuàng)建群組標(biāo)題 GroupHeaderBand group1 = new GroupHeaderBand(); group1.Name =“ GroupHeader1”; group1.Height =單位。厘米* 1; //設(shè)置組條件 group1.Condition =“ [Products.ProductName] .Substring(0,1)”; //將組添加到page.Bands集合 page1.Bands.Add(group1); //創(chuàng)建組頁(yè)腳 group1.GroupFooter =新的GroupFooterBand(); group1.GroupFooter.Name =“ GroupFooter1”; group1.GroupFooter.Height =單位。厘米* 1; //創(chuàng)建DataBand DataBand data1 =新的DataBand(); data1.Name =“ Data1”; data1.Height =單位厘米* 0.5f; //設(shè)置數(shù)據(jù)源 data1.DataSource = report.GetDataSource(“ Products”); //將數(shù)據(jù)帶連接到組 group1.Data = data1; 使用Windows.Forms 23 //創(chuàng)建“文本”對(duì)象 //報(bào)告標(biāo)題 TextObject text1 = new TextObject(); text1.Name =“ Text1”; //設(shè)定界限 text1.Bounds = new RectangleF(0,0, 單位厘米* 19,單位厘米* 1); //設(shè)置文字 text1.Text =“產(chǎn)品”; //設(shè)置外觀 text1.HorzAlign = HorzAlign.Center; text1.Font = new Font(“ Tahoma”,14,F(xiàn)ontStyle.Bold); //將其添加到ReportTitle page1.ReportTitle.Objects.Add(text1); // 團(tuán)體 TextObject text2 = new TextObject(); text2.Name =“ Text2”; text2.Bounds = new RectangleF(0,0, 單位厘米* 2,單位。厘米* 1); text2.Text =“ [[[Products.ProductName] .Substring(0,1)]”; text2.Font = new Font(“ Tahoma”,10,F(xiàn)ontStyle.Bold); //將其添加到GroupHeader group1.Objects.Add(text2); //數(shù)據(jù)帶 TextObject text3 = new TextObject(); text3.Name =“ Text3”; text3.Bounds = new RectangleF(0,0, 單位厘米* 10,單位厘米* 0.5f); text3.Text =“ [Products.ProductName]”; text3.Font = new Font(“ Tahoma”,8); //將其添加到DataBand data1.Objects.Add(text3); //組頁(yè)腳 TextObject text4 = new TextObject(); text4.Name =“ Text4”; text4.Bounds = new RectangleF(0,0, 單位厘米* 10,單位厘米* 0.5f); text4.Text =“計(jì)數(shù):[CountOfProducts]”; text4.Font = new Font(“ Tahoma”,8,F(xiàn)ontStyle.Bold); //將其添加到GroupFooter group1.GroupFooter.Objects.Add(text4); //添加總計(jì) 總計(jì)groupTotal =新的Total(); groupTotal.Name =“ CountOfProducts”; groupTotal.TotalType = TotalType.Count; groupTotal.Evaluator = data1; groupTotal.PrintOn = group1.Footer; //將其添加到報(bào)告總計(jì) report.Dictionary.Totals.Add(groupTotal); //運(yùn)行報(bào)告 report.Show();準(zhǔn)備好的報(bào)告如下:
使用EnvironmentSettings組件(請(qǐng)參見(jiàn)“ FastReport.Net環(huán)境”部分),您可以調(diào)整標(biāo)準(zhǔn)預(yù)覽窗口。相關(guān)屬性包含在EnvironmentSettings.PreviewSettings屬性里面。
如果您由于某些原因不想使用標(biāo)準(zhǔn)預(yù)覽窗口,您可以創(chuàng)建自己的預(yù)覽窗口。要做到這一點(diǎn),請(qǐng)使用可以添加到您的表單上的PreviewControl控件。要在該控件中顯示報(bào)表,請(qǐng)通過(guò)以下代碼將其連接到Report對(duì)象。
report1.Preview = previewControl1;
要準(zhǔn)備一份報(bào)告并在PreviewControl中顯示,請(qǐng)使用Report對(duì)象的Show方法。
report1.Show(); your_form.ShowDialog();或以下代碼:
if (report1.Prepare())
{
report1.ShowPrepared();
your_form.ShowDialog();
}
在這些例子中,your_form是包含PreviewControl的表單。
使用PreviewControl組件的方法,你可以從你的代碼中處理它。您甚至可以使用ToolbarVisible, StatusbarVisible屬性來(lái)關(guān)閉標(biāo)準(zhǔn)工具欄和/或狀態(tài)欄。這在Demos/\C#/CustomPreview示例項(xiàng)目中進(jìn)行了演示。
在數(shù)據(jù)向?qū)е羞^(guò)濾表格
數(shù)據(jù)向?qū)Э梢詮?"數(shù)據(jù)|添加數(shù)據(jù)源... "菜單中調(diào)用。在這里您可以設(shè)置連接并選擇一個(gè)或多個(gè)數(shù)據(jù)表。默認(rèn)情況下,向?qū)?huì)顯示所選連接中的所有可用表。如果您想過(guò)濾不必要的表,請(qǐng)使用 "Config.DesignerSettings.FilterConnectionT "菜單。DesignerSettings.FilterConnectionTables事件。以下示例顯示了如何從表列表中刪除 "表1 "表。
using FastReport.Utils; Config.DesignerSettings.FilterConnectionTables += FilterConnectionTables; private void FilterConnectionTables( 對(duì)象發(fā)送者,F(xiàn)ilterConnectionTablesEventArgs e) { 如果(e.TableName ==“表1”) e.Skip = true; }
還想要更多嗎?可以您點(diǎn)擊閱讀【FastReport的報(bào)表2020最新資源盤(pán)點(diǎn)】,查找需要的教程資源。讓人興奮的是FastReport的.NET正在慧都網(wǎng)火熱銷(xiāo)售中!低至3701元型態(tài)起!> >查看價(jià)格詳情

QQ交談
在線(xiàn)咨詢(xún)

渝公網(wǎng)安備
50010702500608號(hào)

客服熱線(xiàn)