Hur man använder Aspose.Cells.GridWeb med .NET Core
Använd Aspose.Cells.GridWeb med .NET Core
Denna artikel visar hur man använder Aspose.Cells.GridWeb genom att skapa en exempelwebbplats i Visual Studio 2019. Processen har delats upp i steg.
Steg 1: Skapa ett nytt projekt
- Öppna Visual Studio 2019.
- Från Fil-menyn, välj Ny, sedan Projekt. Skapa ett nytt projektfönster öppnas.
- Välj ASP.NET Core Web Application från Visual Studio installerade projektmallar och klicka på Nästa.
- Ange en plats där platsen och namnet på projektet och klicka på Skapa.
- Välj mallen Webbapplikation (Modell-Visnings-Controller) och se till att ASP .NET Core 2.1 är valt.
- Klicka på Skapa.
Steg 2: Kontrollera den initiala vyn
Att köra det nyss skapade projektet visar standardmallen i webbläsaren enligt bilden nedan.
Steg 3: Lägga till Aspose.Cells.GridWeb
- Lägg till följande Nuget-paket i projektet
- Lägg till Aspose.Cells.GridWeb-paket
- Lägg till följande i filen _ViewImports.cshtml i mappen Vy.
This file contains 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
Filen kommer att se ut så här efter modifieringarna
- Lägg följande kod i HomeController’s Index-metod.
//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); |
- Lägg till följande kod i filen Index.cshtml i View > Home-katalogen.
@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> |
Filen kommer se ut så här efter ändringen.
- Lägg till Session-stöd och GridScheduedService i filen Startup.cs.
- Lägg till följande kodsnutt i metoden ConfigureServices.
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>(); |
- Lägg till följande kodsnutt i metoden Configure.
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?}"); | |
}); |
- Placera den senaste acw_client i katalogen: wwwroot/js
- Lägg till AcwController i Controllers för att hantera acw-routekartan som kan tillhandahålla alla standardåtgärder för allmän redigering.
public class AcwController : Controller | |
{ | |
public IActionResult Operation(string type, string id) | |
{ | |
return Aspose.Cells.GridWeb.AcwController.DoAcwAction(this, type, id); | |
} | |
} |
Steg 4: Testa appen
Att köra appen kommer att ge utdata liknande den som visas i bilden nedan.