So verwenden Sie Aspose.Cells.GridWeb mit .NET Core
Contents
[
Hide
]
In diesem Thema wird erläutert, wie Aspose.Cells.GridWeb mit .NET Core-Anwendungen unter Verwendung von Visual Studio.NET 2019 verwendet wird. Dieses Thema ist nützlich für Entwickler auf Anfängerniveau, die mit Aspose.Cells.GridWeb arbeiten.
Verwenden Sie Aspose.Cells.GridWeb mit .NET Core
In diesem Thema wird gezeigt, wie Sie Aspose.Cells.GridWeb verwenden, indem Sie eine Beispielwebsite in Visual Studio 2019 erstellen. Der Prozess wurde in Schritte unterteilt.
Schritt 1: Erstellen eines neuen Projekts
- Öffnen Sie Visual Studio 2019.
- Von demDatei Menü, auswählenNeu , dannProjekt. Der Dialog Neues Projekt erstellen wird geöffnet.
- WählenASP.NET Core-Webanwendung aus Visual Studio installierten Projektvorlagen und klicken Sie aufNächste.
- Geben Sie einen Ort an, wo der Ort und der Name des Projekts und klicken Sie aufSchaffen.
- Wähle ausWebanwendung (Model-View-Controller) Vorlage und stellen Sie sicher, dassASP .NET Kern 2.1 ist ausgewählt.
- KlickenSchaffen.
Schritt 2: Überprüfung der Ausgangsansicht
Beim Ausführen des neu erstellten Projekts wird die Standardvorlage im Browser angezeigt, wie in der Abbildung unten gezeigt.
Schritt 3: Hinzufügen von Aspose.Cells.GridWeb
- Fügen Sie dem Projekt die folgenden Nuget-Pakete hinzu
- Fügen Sie das Paket Aspose.Cells.GridWeb hinzu
- Fügen Sie Folgendes zur Datei _ViewImports.cshtml im Ordner „Views“ hinzu.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
@using Aspose.Cells.GridWeb @addTagHelper *, Aspose.Cells.GridWeb
Die Datei sieht nach den Änderungen so aus
- Fügen Sie den folgenden Code in die Index-Methode des HomeControllers ein.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//set a session store path | |
GridWeb.SessionStorePath = @"D:\Test\tmp\"; | |
GridWeb mw = new GridWeb(); | |
mw.ID = "gid"; | |
mw.SetSession(HttpContext.Session); | |
//set acw_client path | |
mw.ResourceFilePath = "/js/acw_client/"; | |
//load workbook | |
mw.ImportExcelFile("D:\\Book1.xlsx"); | |
//set width height | |
mw.Width = Unit.Pixel(800); | |
mw.Height = Unit.Pixel(500); | |
return View(mw); |
Denken Sie daran, den SessionStorePath und den ImportExcelFile-Pfad zu aktualisieren.
- Fügen Sie den folgenden Code in dieIndex.cshtml Datei im Verzeichnis View > Home.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@model GridWeb | |
<script src="~/js/acw_client/acwmain.js" asp-append-version="true"></script> | |
<script src="~/js/acw_client/lang_en.js" asp-append-version="true"></script> | |
<link href="~/js/acw_client/menu.css" rel="stylesheet" type="text/css"> | |
<div class="text-center"> | |
<GridWebDiv mw=Model></GridWebDiv> | |
</div> |
Die Datei sieht nach der Änderung so aus.
- Fügen Sie Sitzungsunterstützung und GridScheduedService in der Datei „Startup.cs“ hinzu
- Fügen Sie den folgenden Codeausschnitt in der ConfigureServices-Methode hinzu.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.AddSession(options => | |
{ | |
// Set a short timeout for easy testing. | |
options.IdleTimeout = TimeSpan.FromSeconds(3600); | |
options.Cookie.HttpOnly = true; | |
// Make the session cookie essential | |
options.Cookie.IsEssential = true; | |
}); | |
services.AddSingleton<Microsoft.Extensions.Hosting.IHostedService, GridScheduedService>(); |
- Fügen Sie den folgenden Codeausschnitt in der Configure-Methode hinzu.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.UseSession(); | |
app.UseMvc(routes => | |
{ | |
routes.MapRoute("acw", "acw/{type}/{id}", | |
defaults: new { controller = "Acw", action = "Operation" }); | |
routes.MapRoute( | |
name: "default", | |
template: "{controller=Home}/{action=Index}/{id?}"); | |
}); |
- Legen Sie den neuesten acw_client im Verzeichnis ab: wwwroot/js
- AddierenAcwControllerin Controllern, um mit der acw-Routenkarte umzugehen, die alle Standardoperationen für allgemeine Bearbeitungsaktionen bereitstellen kann.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AcwController : Controller | |
{ | |
public IActionResult Operation(string type, string id) | |
{ | |
return Aspose.Cells.GridWeb.AcwController.DoAcwAction(this, type, id); | |
} | |
} |
Schritt 4: Testen Sie die App
Beim Ausführen der App wird die Ausgabe ähnlich der im Bild unten gezeigten ausgegeben.