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

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

yuyutoo 2025-02-04 16:54 4 浏览 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使用教程哦

相关推荐

当 Linux 根分区 (/) 已满时如何释放空间?

根分区(/)是Linux文件系统的核心,包含操作系统核心文件、配置文件、日志文件、缓存和用户数据等。当根分区满载时,系统可能出现无法写入新文件、应用程序崩溃甚至无法启动的情况。常见原因包括:...

玩转 Linux 之:磁盘分区、挂载知多少?

今天来聊聊linux下磁盘分区、挂载的问题,篇幅所限,不会聊的太底层,纯当科普!!1、Linux分区简介1.1主分区vs扩展分区硬盘分区表中最多能存储四个分区,但我们实际使用时一般只分为两...

Linux 文件搜索神器 find 实战详解,建议收藏

在Linux系统使用中,作为一个管理员,我希望能查找系统中所有的大小超过200M文件,查看近7天系统中哪些文件被修改过,找出所有子目录中的可执行文件,这些任务需求...

Linux 操作系统磁盘操作(linux 磁盘命令)

一、文档介绍本文档描述Linux操作系统下多种场景下的磁盘操作情况。二、名词解释...

Win10新版19603推送:一键清理磁盘空间、首次集成Linux文件管理器

继上周四的Build19592后,微软今晨面向快速通道的Insider会员推送Windows10新预览版,操作系统版本号Build19603。除了一些常规修复,本次更新还带了不少新功能,一起来了...

Android 16允许Linux终端使用手机全部存储空间

IT之家4月20日消息,谷歌Pixel手机正朝着成为强大便携式计算设备的目标迈进。2025年3月的更新中,Linux终端应用的推出为这一转变奠定了重要基础。该应用允许兼容的安卓设备...

Linux 系统管理大容量磁盘(2TB+)操作指南

对于容量超过2TB的磁盘,传统MBR分区表的32位寻址机制存在限制(最大支持2.2TB)。需采用GPT(GUIDPartitionTable)分区方案,其支持64位寻址,理论上限为9.4ZB(9....

Linux 服务器上查看磁盘类型的方法

方法1:使用lsblk命令lsblk输出说明:TYPE列显示设备类型,如disk(物理磁盘)、part(分区)、rom(只读存储)等。...

ESXI7虚机上的Ubuntu Linux 22.04 LVM空间扩容操作记录

本人在实际的使用中经常遇到Vmware上安装的Linux虚机的LVM扩容情况,最终实现lv的扩容,大多数情况因为虚机都是有备用或者可停机的情况,一般情况下通过添加一块物理盘再加入vg,然后扩容lv来实...

5.4K Star很容易!Windows读取Linux磁盘格式工具

[开源日记],分享10k+Star的优质开源项目...

Linux 文件系统监控:用脚本自动化磁盘空间管理

在Linux系统中,文件系统监控是一项非常重要的任务,它可以帮助我们及时发现磁盘空间不足的问题,避免因磁盘满而导致的系统服务不可用。通过编写脚本自动化磁盘空间管理,我们可以更加高效地处理这一问题。下面...

Linux磁盘管理LVM实战(linux实验磁盘管理)

LVM(逻辑卷管理器,LogicalVolumeManager)是一种在Linux系统中用于灵活管理磁盘空间的技术,通过将物理磁盘抽象为逻辑卷,实现动态调整存储容量、跨磁盘扩展等功能。本章节...

Linux查看文件大小:`ls`和`du`为何结果不同?一文讲透原理!

Linux查看文件大小:ls和du为何结果不同?一文讲透原理!在Linux运维中,查看文件大小是日常高频操作。但你是否遇到过以下困惑?...

使用 df 命令检查服务器磁盘满了,但用 du 命令发现实际小于磁盘容量

在Linux系统中,管理员或开发者经常会遇到一个令人困惑的问题:使用...

Linux磁盘爆满紧急救援指南:5步清理释放50GB+小白也能轻松搞定

“服务器卡死?网站崩溃?当Linux系统弹出‘Nospaceleft’的红色警报,别慌!本文手把手教你从‘删库到跑路’进阶为‘磁盘清理大师’,5个关键步骤+30条救命命令,快速释放磁盘空间,拯救你...

取消回复欢迎 发表评论: