Come usare Aspose.Cells.GridWeb con .NET Core
Contents
[
Hide
]
Questo argomento spiega come usare Aspose.Cells.GridWeb con le applicazioni .NET Core usando Visual Studio.NET 2019. Questo argomento è utile per gli sviluppatori di livello principiante che lavorano con Aspose.Cells.GridWeb.
Usa Aspose.Cells.GridWeb con .NET Core
Questo argomento illustra come usare Aspose.Cells.GridWeb creando un sito Web di esempio in Visual Studio 2019. Il processo è stato suddiviso in passaggi.
Passaggio 1: creazione di un nuovo progetto
- Apri Visual Studio 2019.
- DalFile menù, selezionareNuovo , poiProgetto. Viene aperta la finestra di dialogo Crea un nuovo progetto.
- SelezionareASP.NET Applicazione Web principale dai modelli di progetto installati di Visual Studio e fare clic suProssimo.
- Specificare una posizione in cui la posizione e il nome del progetto e fare clicCreare.
- Seleziona ilApplicazione Web (Model-View-Controller) modello e assicurati cheASP .NET Nucleo 2.1 è selezionato.
- ClicCreare.
Passaggio 2: controllo della vista iniziale
L’esecuzione del progetto appena creato mostra il modello predefinito nel browser, come mostrato nell’immagine sottostante.
Passaggio 3: aggiunta di Aspose.Cells.GridWeb
- Aggiungere i seguenti pacchetti Nuget al progetto
- Aggiungere il pacchetto Aspose.Cells.GridWeb
- Aggiungi quanto segue al file _ViewImports.cshtml nella cartella 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
Il file avrà questo aspetto dopo le modifiche
- Inserisci il seguente codice nel metodo Index di HomeController.
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); |
Ricordarsi di aggiornare SessionStorePath e il percorso ImportExcelFile.
- Aggiungere il seguente codice nel fileIndex.cshtml file nella directory Visualizza > Home.
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> |
Il file avrà questo aspetto dopo la modifica.
- Aggiungere il supporto della sessione e GridScheduedService nel file Startup.cs
- Aggiungere il seguente frammento di codice nel metodo 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>(); |
- Aggiungere il frammento di codice seguente nel metodo Configure.
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?}"); | |
}); |
- Metti l’ultimo acw_client nella directory: wwwroot/js
- AggiungereAcwControllernei controller per gestire la mappa del percorso acw che può fornire tutte le operazioni predefinite per l’azione di modifica generale.
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); | |
} | |
} |
Passaggio 4: prova l’app
L’esecuzione dell’app produrrà un output simile a quello mostrato nell’immagine sottostante.