翻譯|使用教程|編輯:吉煒煒|2025-03-10 16:40:28.250|閱讀 93 次
概述:本文將探討如何使用嵌入式查看器組件在 ASP.NET Core Web 應(yīng)用程序中創(chuàng)建報告和儀表板的示例。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Stimulsoft Ultimate (原Stimulsoft Reports.Ultimate)是用于創(chuàng)建報表和儀表板的通用工具集。該產(chǎn)品包括用于WinForms、ASP.NET、.NET Core、JavaScript、WPF、PHP、Java和其他環(huán)境的完整工具集。無需比較產(chǎn)品功能,Stimulsoft Ultimate包含了所有內(nèi)容!
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Stimulsoft.Report; using Stimulsoft.Report.Angular; using Stimulsoft.Report.Web; namespace AngularViewer.Controllers { [Controller] public class ViewerController : Controller { static ViewerController() { // How to Activate //Stimulsoft.Base.StiLicense.Key = "6vJhGtLLLz2GNviWmUTrhSqnO..."; //Stimulsoft.Base.StiLicense.LoadFromFile("license.key"); //Stimulsoft.Base.StiLicense.LoadFromStream(stream); } [HttpPost] public IActionResult InitViewer() { var requestParams = StiAngularViewer.GetRequestParams(this); var options = new StiAngularViewerOptions(); options.Actions.GetReport = "GetReport"; options.Actions.ViewerEvent = "ViewerEvent"; options.Appearance.ScrollbarsMode = true; return StiAngularViewer.ViewerDataResult(requestParams, options); } [HttpPost] public IActionResult GetReport() { var report = StiReport.CreateNewReport(); var path = StiAngularHelper.MapPath(this, $"Reports/MasterDetail.mrt"); report.Load(path); return StiAngularViewer.GetReportResult(this, report); } [HttpPost] public IActionResult ViewerEvent() { return StiAngularViewer.ViewerEventResult(this); } } }
此外,您還應(yīng)通過啟用 CORS 策略和定義 Angular 的回退機制來配置 .NET 服務(wù)器。這應(yīng)在Program.cs文件中完成。
Program.cs
接下來,在文件資源管理器 中打開項目文件夾,并使用npm安裝必要的 Angular-client 組件。using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllersWithViews(); builder.Services.AddCors(options => { options.AddDefaultPolicy(policy => { policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod(); }); }); var app = builder.Build(); if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error"); } app.UseDefaultFiles(); app.UseStaticFiles(); app.UseRouting(); app.UseCors(); app.UseAuthorization(); app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); app.Use(async (context, next) => { await next(); if (context.Response.StatusCode == 404 && !context.Request.Path.Value.StartsWith("/api")) { context.Request.Path = "/index.html"; await next(); } }); app.Run();
關(guān)閉控制臺,刪除ClientApp文件夾,重新打開控制臺,輸入以下命令:npm install stimulsoft-viewer-angular
選擇CSS格式,按Enter,關(guān)閉控制臺,然后導(dǎo)航到ClientApp文件夾。ng new ClientApp
關(guān)閉控制臺。在文本編輯器中打開目錄“ ...ClientApp\src\app\ ”中的app.module.ts文件并添加StimulsoftViewerModule。然后將以下代碼插入app.module.ts:app.module.tsnpm install stimulsoft-viewer-angular
在文本編輯器中打開目錄“ ...ClientApp\src\app\ ”中的app.component.html文件并添加AppComponent。然后將以下代碼插入app.component.html:app.component.htmlimport { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { StimulsoftViewerModule } from 'stimulsoft-viewer-angular'; import { HttpClientModule } from '@angular/common/http'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { FormsModule } from '@angular/forms'; import { AppComponent } from './app.component'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, StimulsoftViewerModule, HttpClientModule, BrowserAnimationsModule, FormsModule, ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
轉(zhuǎn)到 Visual Studio 并運行項目。您將看到一個帶有指定報告的查看器。<stimulsoft-viewer-angular [requestUrl]="'//localhost:5151/Viewer/{action}'" [action]="'InitViewer'" [height]="'100vh'" ></stimulsoft-viewer-angular>
---------------------------------------------------------------------------
關(guān)于慧都科技:
慧都科技是專注軟件工程、智能制造、石油工程三大行業(yè)的數(shù)字化解決方案服務(wù)商。在軟件工程領(lǐng)域,我們提供開發(fā)控件、研發(fā)管理、代碼開發(fā)、部署運維等軟件開發(fā)全鏈路所需的產(chǎn)品,提供正版授權(quán)采購、技術(shù)選型、個性化維保等服務(wù),幫助客戶實現(xiàn)技術(shù)合規(guī)、降本增效與風險可控。慧都科技是Stimulsoft的在中國區(qū)的合作伙伴,Stimulsoft作為圖表報表領(lǐng)域的優(yōu)秀產(chǎn)品,幫助企業(yè)實現(xiàn)輕松構(gòu)建高性能的表格報告及圖表。
下載|體驗更多Stimulsoft產(chǎn)品,請咨詢,或撥打產(chǎn)品熱線:023-68661681
加入圖表報表技術(shù)交流QQ群(740060302),與更多小伙伴一起探討提升開發(fā)技能。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都網(wǎng)