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

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

如何使用FastReport .NET 在 JetBrains Rider 中创建PDF 告? 下一步是设置项目。在.NET/.NET Core部分选择桌面应用程序项目类型。然后给项目命名,我们以 “ReportPDF_Core_WinFormsApp “为例。然后点击Windows Forms App类型,C#语言,NET 7.0框架。

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

我们首先需要在应用代码中为我们的 告添加一个简单的样本数据集,请在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 选项卡,然后单击源选项卡。

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

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

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

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

您将看到相应的存储库:

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

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

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

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

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

接下来在Form1.cs中添加:

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

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

  // <summary> // Required method for Designer support - do not modify // the contents of this method with the code editor. // </summary> 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 在 JetBrains Rider 中创建PDF 告?

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

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

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

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

让我们将我们的 告模板保存在 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”按钮:

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

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

如何使用FastReport .NET 在 JetBrains Rider 中创建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 旁边:

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

关于“使用FastReport .NET 从 JetBrains Rider 中创建PDF 告的教程就到这里了,点击查看更多FastReport .Net使用教程

FastReport .Net | 下载试用

FastReport技术

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年11月16日
下一篇 2022年11月17日

相关推荐

发表回复

登录后才能评论