网站首页 > 开源技术 正文
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 进行适当的更改:
// <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 设计器。
让我们使用拖放操作将数据集中的字段添加到报告模板,然后将“员工”标题添加到报告中。之后,为文本对象设置 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使用教程哦。
猜你喜欢
- 2024-10-26 脚下每一步都是马赛克艺术(脚下走的每一步)
- 2024-10-26 Python GUI开发:PySide2使用入门(python gui程序)
- 2024-10-26 手把手教会 VS2022 设计 Winform 高DPI兼容程序 (net461 net6.0 双出)
- 2024-10-26 实战PyQt5: 002-安装和配置PyQt5开发环境
- 2024-10-26 触得到的时间--kickstarter上受到最多资助的项目
- 2024-10-26 今天再用10分钟,木辛老师带你一起走入界面布局管理的知识海洋吧
- 2024-10-26 51款工业风浴室超高逼格做法,真是太好用了
- 2024-10-26 由浅入深理解C#中的事件(c#事件的五要素)
- 2024-10-26 PYQT5学习(02):利用Qt Designer制作第一个窗口程序
- 2024-10-26 132.Python——PySide6:安装和VSCode中配置及使用
你 发表评论:
欢迎- 05-08Peking Opera Featuring National Treasure Min Fanglei Premiers in Changsha
- 05-08安卓版Opera Mini浏览器更新,增强大屏设备支持
- 05-08Opera 36.0开发者版本发布:个性化新闻+简化菜单
- 05-08Vitas发布20周年专辑《OPERA20》首支单曲
- 05-08Android 版 Opera 89 带来了大量标签页改进
- 05-08基本Spring Cloud的微服务架构搭建及应用(一)
- 05-08代码质量扫描工具SonarQube原理及环境搭建
- 05-08小心!你的这些习惯和粗心,可能正在泄露信息!丨提示
- 最近发表
-
- Peking Opera Featuring National Treasure Min Fanglei Premiers in Changsha
- 安卓版Opera Mini浏览器更新,增强大屏设备支持
- Opera 36.0开发者版本发布:个性化新闻+简化菜单
- Vitas发布20周年专辑《OPERA20》首支单曲
- Android 版 Opera 89 带来了大量标签页改进
- 基本Spring Cloud的微服务架构搭建及应用(一)
- 代码质量扫描工具SonarQube原理及环境搭建
- 小心!你的这些习惯和粗心,可能正在泄露信息!丨提示
- 一步步搭建openwrt编译环境并编译ddserver源码
- 远程办公、巡逻机器人、口罩识别……离不开一群“研发技术宅”
- 标签列表
-
- jdk (81)
- putty (66)
- rufus (78)
- 内网穿透 (89)
- okhttp (70)
- powertoys (74)
- windowsterminal (81)
- netcat (65)
- ghostscript (65)
- veracrypt (65)
- asp.netcore (70)
- wrk (67)
- aspose.words (80)
- itk (80)
- ajaxfileupload.js (66)
- sqlhelper (67)
- express.js (67)
- phpmailer (67)
- xjar (70)
- redisclient (78)
- wakeonlan (66)
- tinygo (85)
- startbbs (72)
- webftp (82)
- vsvim (79)
本文暂时没有评论,来添加一个吧(●'◡'●)