Stimulsoft Ultimate (原Stimulsoft Reports.Ultimate)是用于创建报表和仪表板的通用工具集。该产品包括用于WinForms、ASP.NET、.NET Core、JavaScript、WPF、PHP、Java和其他环境的完整工具集。无需比较产品功能,Stimulsoft Ultimate包含了所有内容!
WinUI是适用于 Windows 桌面应用程序的用户界面 (UI) 框架,包括使用 C# 和 .NET 的托管应用程序,以及使用 C++ 和 Win32 API 的本机应用程序。WinUI 3 使用最新的 UI 模式提供一致、直观且易于访问的体验。Stimulsoft 没有专门针对WinUI 的解决方案;但是,要嵌入报告系统,您可以使用Stimulsoft.Reports.Web.NetCore组件,如果需要集成分析系统,则可以使用Stimulsoft.Dashboards.Web.NetCore组件。重要提示!
.NET Core 的报告工具允许您创建任何复杂程度的报告,从标准发票到具有参数、交互式排序和向下钻取功能的复杂文档。但是,WinUI框架的本机可视化组件、报告查看器和报告设计器不可用,并且 .NET Core 包中的组件可能会表现得不可预测。这是由于WinUI框架本身的某些特性造成的。因此,目前我们不建议将查看器或设计器嵌入到WinUI项目中。
.NET Core 的报告工具允许您创建任何复杂程度的报告,从标准发票到具有参数、交互式排序和向下钻取功能的复杂文档。但是,WinUI框架的本机可视化组件、报告查看器和报告设计器不可用,并且 .NET Core 包中的组件可能会表现得不可预测。这是由于WinUI框架本身的某些特性造成的。因此,目前我们不建议将查看器或设计器嵌入到WinUI项目中。同时,仍可以生成报告并将其显示为导出结果,例如PDF文件或HTML。必须事先安装Windows App SDK C# 模板包。在 Visual Studio 安装程序中,此SDK位于.NET 桌面开发类别下。
步骤 1
首先,创建并初始化一个新的WinUI项目 - Blank App, Packaged (WinUI 3 in Desktop)。
第 2 步
创建空白应用程序打包(桌面版 WinUI 3)时,它已经包含一个演示项目,我们将在其中集成我们的工具。首先,将所需的 NuGet 包安装到这个演示项目中:用于报告的Stimulsoft.Reports.Web.NetCore,或如果还需要数据分析,则安装Stimulsoft.Dashboards.Web.NetCore 。
步骤3
将报告文件添加到项目。这些可以是报告或仪表板模板(`*.mrt、*.mrz、*.mrx`),以及生成的报告文件(`*.mdc、*.mdz、*.mdx`)。例如,将Invoice.mrt报告模板添加到Assets文件夹。注意!
要使文件可访问,请将其“构建操作”属性设置为“嵌入式资源”。
步骤4
接下来,在MainWindow.xaml文件中,添加用于显示WebView2 的标记:
MainWindow.xaml
<?xml version="1.0" encoding="utf-8"?> <Window x:Class="App1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:App1" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Title="App1"> <Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch"> <Grid.RowDefinitions> <RowDefinition Height="100" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <Button x:Name="button" HorizontalAlignment="Center" VerticalAlignment="Center" Content="Click To Show Report" Click="Button_Click" /> <WebView2 x:Name="webView" Grid.Row="1" />> </Grid> </Window>
步骤5
这一步在MainWindow.xaml.cs文件 中添加代码,用于在处理“按钮点击”事件时在WebView2中加载并显示报表:MainWindow.xaml.cs
using System; using System.IO; using System.Reflection; using Microsoft.UI.Xaml; using Stimulsoft.Report; using Stimulsoft.Report.Export; // To learn more about WinUI, the WinUI project structure, // and more about our project templates, see: http://aka.ms/winui-project-info. namespace App1 { /// <summary> /// An empty window that can be used on its own or navigated to within a Frame. /// </summary> public sealed partial class MainWindow : Window { public MainWindow() { this.InitializeComponent(); } private async void Button_Click(object sender, RoutedEventArgs e) { button.Content = "Clicked"; // Load the report var report = new StiReport(); var reportStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("App1.Assets.Christmas.mrt"); report.Load(reportStream); // Export the report to PDF report.Render(); using var pdfStream = new MemoryStream(); report.ExportDocument(StiExportFormat.Pdf, pdfStream, new StiPdfExportSettings()); var pdfString = Convert.ToBase64String(pdfStream.ToArray()); await webView.EnsureCoreWebView2Async(); // Display the PDF in a WebView2 control webView.NavigateToString( @$"<html><head></head><body><div><object type=""application/pdf"" width=""100%"" height=""100%"" data=""data:application/pdf;base64,{pdfString}""></object></div></body></html>"); } } }
因此,在开发空白应用程序、打包(桌面版 WinUI 3)应用程序时,无需集成报告查看器或设计器即可使用报告和数据分析系统。有关使用 .NET Core Stimulsoft 的更多详细信息,请参阅文档。Stimulsoft.Reports.Web.NetCore的激活可通过Reports.WEB订阅获得,而Stimulsoft.Dashboards.Web.NetCore则需要Dashboards.WEB订阅。此外,可以在网上商店购买 用于跨多个平台报告和分析的综合解决方案Stimulsoft Ultimate 。