Hur man använder Aspose.Cells.GridWeb med .NET Core
Contents
[
Hide
]
Det här avsnittet förklarar hur du använder Aspose.Cells.GridWeb med .NET Kärnapplikationer som använder Visual Studio.NET 2019. Det här ämnet är användbart för utvecklare på nybörjarnivå som arbetar med Aspose.Cells.GridWeb.
Använd Aspose.Cells.GridWeb med .NET Core
Det här ämnet visar hur du använder Aspose.Cells.GridWeb genom att göra en exempelwebbplats i Visual Studio 2019. Processen har delats upp i steg.
Steg 1: Skapa ett nytt projekt
- Öppna Visual Studio 2019.
- FrånFil menyn, väljNy , dåProjekt. Skapa ett nytt projekt dialogrutan öppnas.
- VäljASP.NET Core Web Application från Visual Studio installerade projektmallar och klickaNästa.
- Ange en plats där platsen och namnet på projektet och klickaSkapa.
- VäljWebbapplikation (Model-View-Controller) mall och se till attASP .NET Core 2.1 är vald.
- KlickSkapa.
Steg 2: Kontrollera den ursprungliga vyn
Att köra det nyskapade projektet visar standardmallen i webbläsaren som visas i bilden nedan.
Steg 3: Lägger till Aspose.Cells.GridWeb
- Lägg till följande Nuget-paket till projektet
- Lägg till Aspose.Cells.GridWeb Package
- Lägg till följande i filen _ViewImports.cshtml i mappen Views.
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 ändringarna
- Lägg in följande kod i HomeController’s Index-metoden.
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
//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); |
Kom ihåg att uppdatera SessionStorePath och ImportExcelFile-sökvägen.
- Lägg till följande kod iIndex.cshtml fil i Visa > Hemkatalog.
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
@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 att se ut så här efter ändringen.
- Lägg till sessionsstöd och GridScheduedService i filen Startup.cs
- Lägg till följande kodavsnitt i metoden ConfigureServices.
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
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 kodavsnitt i konfigureringsmetoden.
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
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?}"); | |
}); |
- Lägg den senaste acw_clienten i katalogen: wwwroot/js
- Lägg tillAcwController Controllers för att hantera acw-ruttkartan som kan tillhandahålla alla standardoperationer för allmänna redigeringsåtgärder.
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
public class AcwController : Controller | |
{ | |
public IActionResult Operation(string type, string id) | |
{ | |
return Aspose.Cells.GridWeb.AcwController.DoAcwAction(this, type, id); | |
} | |
} |
Steg 4: Testa appen
Om du kör appen kommer resultatet att likna det som visas i bilden nedan.