百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 编程网 > 正文

如何使用FastReport .NET 在 JetBrains Rider 中创建PDF报告?

yuyutoo 2025-02-04 16:54 1 浏览 0 评论

Fastreport是目前世界上主流的图表控件,具有超高性价比,以更具成本优势的价格,便能提供功能齐全的报表解决方案,连续三年蝉联全球文档创建组件和库的“ Top 50 Publishers”奖。

FastReport .Net官方最新版免费下载试用,历史版本下载,在线文档和帮助文件下载-慧都网

在本文中,我们将在不使用 Microsoft Visual Studio 的情况下了解 Windows 11 中的 .NET 平台,并创建可导出为 PDF 的报告。与Visual Studio 相似的是 JetBrains Ride,它是由 JetBrains 开发的跨平台 .NET IDE,支持 C#、VB.NET 和 F# 语言。接下来,我们将演示如何使用 FastReport .NET 从 JetBrains Rider 创建、构建和导出 PDF 报告/文档。

第一步,您需要在电脑上安装 JetBrains Rider IDE。接下来,通过选择“New Solution ”创建一个新的解决方案。

下一步是设置项目。在.NET/.NET Core部分选择桌面应用程序项目类型。然后给项目命名,我们以 "ReportPDF_Core_WinFormsApp "为例。然后点击Windows Forms App类型,C#语言,NET 7.0框架。

我们首先需要在应用代码中为我们的报告添加一个简单的样本数据集,请在Form1.cs中添加:

 using System.Data; 

接下来,在Form1类中添加一个私有字段。

 private DataSet _fDataSet = new DataSet();

让我们添加一个私有的CreateDataSet方法,在这里我们将创建并填入一个数据集:

  private void CreateDataSet()
 {
 // create simple dataset with one table 
 // create simple dataset
 _fDataSet = new DataSet(); 
 // create a table
 DataTable table = new DataTable();
 table.TableName = "Employees";
 // adding a table to the dataset
 _fDataSet.Tables.Add(table);
 // adding data to a table 
 table.Columns.Add("ID", typeof(int));
 table.Columns.Add("Name", typeof(string));
 
 table.Rows.Add(1, "Andrew Fuller");
 table.Rows.Add(2, "Nancy Davolio");
 table.Rows.Add(3, "Margaret Peacock");
 }

添加对CreateDataSet方法的调用:

 public Form1()
 {
 InitializeComponent();
 CreateDataSet();
 }

在 JetBrains Rider 中让 FastReport .NET 运行得最快方法是什么?那就是使用快速报告私有 NuGet 服务器

接下来我们介绍在购买FastReport .NET后如何添加 NuGet 包。首选您需要单击 IDE 底部的 NuGet 选项卡,然后单击源选项卡。

现在我们通过单击“+”并输入必要的数据来添加一个新的存储库:

- 名称 — 不带空格的源名称(例如 FR-Nuget);
- 网址——https://nuget.fast-report.com/api/v3/index.json;
- 用户——来自 Fast Reports 帐户的电子邮件;
- 密码 ― Fast Reports 帐户的密码。

您将看到相应的存储库:

现在我们将安装 FastReport.Pro 包。为此,请转到“包”选项卡并按 FR-Nuget 存储库过滤包。当然,安装找到的包。

如果成功,您将看到一条通知。

接下来在Form1.cs中添加:

 public Form1()
 {
 InitializeComponent();
 CreateDataSet();
 }

接下来,我们将在应用程序中插入 3 个新按钮:“报表设计”、“使用对话框导出为 PDF”、“无提示导出”。为此,对 Form1.Designer.cs 进行适当的更改:

  // 
 // Required method for Designer support - do not modify
 // the contents of this method with the code editor.
 // 
 private void InitializeComponent()
 {
 this.components = new System.ComponentModel.Container();
 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
 this.ClientSize = new System.Drawing.Size(800, 450);
 this.Text = "Form1";
 this.btnExportWithDialog = new System.Windows.Forms.Button();
 this.btnSilentExport = new System.Windows.Forms.Button();
 this.btnShowDesigner = new System.Windows.Forms.Button();
 this.SuspendLayout();
 // 
 // btnExportWithDialog
 // 
 this.btnExportWithDialog.Location = new System.Drawing.Point(44, 148);
 this.btnExportWithDialog.Name = "btnExportWithDialog";
 this.btnExportWithDialog.Size = new System.Drawing.Size(208, 23);
 this.btnExportWithDialog.TabIndex = 0;
 this.btnExportWithDialog.Text = "Export to PDF with dialog";
 this.btnExportWithDialog.UseVisualStyleBackColor = true;
 this.btnExportWithDialog.Click += new System.EventHandler(this.btnExportWithDialog_Click);
 // 
 // btnSilentExport
 // 
 this.btnSilentExport.Location = new System.Drawing.Point(44, 180);
 this.btnSilentExport.Name = "btnSilentExport";
 this.btnSilentExport.Size = new System.Drawing.Size(208, 23);
 this.btnSilentExport.TabIndex = 0;
 this.btnSilentExport.Text = "Silent export";
 this.btnSilentExport.UseVisualStyleBackColor = true;
 this.btnSilentExport.Click += new System.EventHandler(this.btnSilentExport_Click);
 // 
 // btnShowDesigner
 // 
 this.btnShowDesigner.Location = new System.Drawing.Point(44, 87);
 this.btnShowDesigner.Name = "btnShowDesigner";
 this.btnShowDesigner.Size = new System.Drawing.Size(208, 23);
 this.btnShowDesigner.TabIndex = 1;
 this.btnShowDesigner.Text = "Report design";
 this.btnShowDesigner.UseVisualStyleBackColor = true;
 this.btnShowDesigner.Click += new System.EventHandler(this.btnShowDesigner_Click);
 // 
 // Form1
 // 
 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
 this.ClientSize = new System.Drawing.Size(292, 266);
 this.Controls.Add(this.btnShowDesigner);
 this.Controls.Add(this.btnSilentExport);
 this.Controls.Add(this.btnExportWithDialog);
 this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
 this.Name = "Form1";
 this.Text = "ExportToPDF";
 this.ResumeLayout(false);
 }
 #endregion
 private System.Windows.Forms.Button btnExportWithDialog;
 private System.Windows.Forms.Button btnSilentExport;
 private System.Windows.Forms.Button btnShowDesigner; 

让我们使用这段代码为“报表设计”按钮编写一个点击处理程序。

 private void btnShowDesigner_Click(object sender, EventArgs e)
 {
 // create report instance
 Report report = new Report();
 // load the existing report
 //report.Load(@"..\..\..\Report.frx");
 // register the dataset
 report.RegisterData(_fDataSet);
 report.GetDataSource("Employees").Enabled = true;
 // run the designer
 report.Design(); 
 // free resources used by report
 report.Dispose();
 }

运行应用程序并查看带有 3 个按钮的表单。

单击“报表设计”按钮并转到 FastReport .NET 设计器。

让我们使用拖放操作将数据集中的字段添加到报告模板,然后将“员工”标题添加到报告中。之后,为文本对象设置 AutoWidth = true 属性。

让我们将我们的报告模板保存在 ReportPDF_Core_WinFormsApp 项目所在的文件夹中,名称为“Report”。保存后,关闭设计器和应用程序。让我们取消注释 btnExportWithDialog_Click 方法中的行,以便在打开设计器时加载我们保存的报表:

  report.Load(@"..\..\..\Report.frx");

为带有对话框的“导出为 PDF”按钮添加点击处理程序:

  private void btnExportWithDialog_Click(object sender, EventArgs e)
 {
 // create report instance
 Report report = new Report();
 // load the existing report
 report.Load(@"..\..\..\Report.frx");
 // register the dataset
 report.RegisterData(_fDataSet);
 // run the report
 report.Prepare();
 // create export instance
 PDFExport export = new PDFExport();
 export.Export(report);
 // free resources used by report
 report.Dispose();
 }

运行项目并单击“使用对话框导出为 PDF”按钮:

将打开一个包含 PDF 导出设置的对话框。选择“导出后打开”并单击“确定”。保存到名为“Report”的 PDF 项目文件夹。导出完成后,PDF文件会自动打开:

因此,我们得到了一个从数据集构建的简单报告/PDF 文档。

我们还要检查所谓的没有对话框的“静默”PDF 导出选项。为“静默导出”按钮添加点击处理程序:

private void btnSilentExport_Click(object sender, EventArgs e)
 {
 // create report instance
 Report report = new Report();
 // load the existing report
 report.Load(@"..\..\..\Report.frx");
 // register the dataset
 report.RegisterData(_fDataSet);
 // run the report
 report.Prepare();
 // run the report
 PDFExport export = new PDFExport();
 // opening after export
 export.OpenAfterExport = true;
 // export the report
 report.Export(export, "Result.pdf");
 // free resources used by report
 report.Dispose();
 }

运行项目并单击“静默导出”按钮。它将立即导出并打开一个名为“结果”的 PDF 文件,它位于正在运行的项目的 exe 旁边:

在本文中,我们回顾了JetBrains Rider (C#) + .NET Core + WinForms + FastReport .NET + Windows 11的拉力,并收到了从数据集构建的 PDF 报告。当然,我们确保无需 Microsoft Visual Studio 即可轻松使用 .NET 平台。

关于“使用FastReport .NET 从 JetBrains Rider 中创建PDF报告”的教程就到这里了,关注我了解更多FastReport .Net使用教程哦

相关推荐

史上最全的浏览器兼容性问题和解决方案

微信ID:WEB_wysj(点击关注)◎◎◎◎◎◎◎◎◎一┳═┻︻▄(页底留言开放,欢迎来吐槽)●●●...

平面设计基础知识_平面设计基础知识实验收获与总结
平面设计基础知识_平面设计基础知识实验收获与总结

CSS构造颜色,背景与图像1.使用span更好的控制文本中局部区域的文本:文本;2.使用display属性提供区块转变:display:inline(是内联的...

2025-02-21 16:01 yuyutoo

写作排版简单三步就行-工具篇_作文排版模板

和我们工作中日常word排版内部交流不同,这篇教程介绍的写作排版主要是用于“微信公众号、头条号”网络展示。写作展现的是我的思考,排版是让写作在网格上更好地展现。在写作上花费时间是有累积复利优势的,在排...

写一个2048的游戏_2048小游戏功能实现

1.创建HTML文件1.打开一个文本编辑器,例如Notepad++、SublimeText、VisualStudioCode等。2.将以下HTML代码复制并粘贴到文本编辑器中:html...

今天你穿“短袖”了吗?青岛最高23℃!接下来几天气温更刺激……

  最近的天气暖和得让很多小伙伴们喊“热”!!!  昨天的气温到底升得有多高呢?你家有没有榜上有名?...

CSS不规则卡片,纯CSS制作优惠券样式,CSS实现锯齿样式

之前也有写过CSS优惠券样式《CSS3径向渐变实现优惠券波浪造型》,这次再来温习一遍,并且将更为详细的讲解,从布局到具体样式说明,最后定义CSS变量,自定义主题颜色。布局...

柠檬科技肖勃飞:大数据风控助力信用社会建设

...

你的自我界限够强大吗?_你的自我界限够强大吗英文

我的结果:A、该设立新的界限...

行内元素与块级元素,以及区别_行内元素和块级元素有什么区别?

行内元素与块级元素首先,CSS规范规定,每个元素都有display属性,确定该元素的类型,每个元素都有默认的display值,分别为块级(block)、行内(inline)。块级元素:(以下列举比较常...

让“成都速度”跑得潇潇洒洒,地上地下共享轨交繁华
让“成都速度”跑得潇潇洒洒,地上地下共享轨交繁华

去年的两会期间,习近平总书记在参加人大会议四川代表团审议时,对治蜀兴川提出了明确要求,指明了前行方向,并带来了“祝四川人民的生活越来越安逸”的美好祝福。又是一年...

2025-02-21 16:00 yuyutoo

今年国家综合性消防救援队伍计划招录消防员15000名

记者24日从应急管理部获悉,国家综合性消防救援队伍2023年消防员招录工作已正式启动。今年共计划招录消防员15000名,其中高校应届毕业生5000名、退役士兵5000名、社会青年5000名。本次招录的...

一起盘点最新 Chrome v133 的5大主流特性 ?

1.CSS的高级attr()方法CSSattr()函数是CSSLevel5中用于检索DOM元素的属性值并将其用于CSS属性值,类似于var()函数替换自定义属性值的方式。...

竞走团体世锦赛5月太仓举行 世界冠军杨家玉担任形象大使

style="text-align:center;"data-mce-style="text-align:...

学物理能做什么?_学物理能做什么 卢昌海

作者:曹则贤中国科学院物理研究所原标题:《物理学:ASourceofPowerforMan》在2006年中央电视台《对话》栏目的某期节目中,主持人问过我一个的问题:“学物理的人,如果日后不...

你不知道的关于这只眯眼兔的6个小秘密
你不知道的关于这只眯眼兔的6个小秘密

在你们忙着给熊本君做表情包的时候,要知道,最先在网络上引起轰动的可是这只脸上只有两条缝的兔子——兔斯基。今年,它更是迎来了自己的10岁生日。①关于德艺双馨“老艺...

2025-02-21 16:00 yuyutoo

取消回复欢迎 发表评论: