.NET コアで Aspose.Cells.GridWeb を使用する方法
Contents
[
Hide
]
このトピックでは、Visual Studio.NET 2019 を使用して .NET コア アプリケーションで Aspose.Cells.GridWeb を使用する方法について説明します。
.NETコアでAspose.Cells.GridWebを使用
このトピックでは、Visual Studio 2019 でサンプル Web サイトを作成して、Aspose.Cells.GridWeb を使用する方法を示します。プロセスはステップに分割されています。
ステップ 1: 新しいプロジェクトの作成
- Visual Studio 2019 を開きます。
- からファイルメニュー、選択新しい、 それから計画. 新規プロジェクトの作成ダイアログが開きます。
- 選択するASP.NET コア Web アプリケーションVisual Studio にインストールされたプロジェクト テンプレートから、次.
- プロジェクトの場所と名前を指定してクリックします作成.
- を選択**Web アプリケーション (Model-View-Controller)**テンプレートを作成し、ASP .NET コア 2.1が選択されます。
- クリック作成.
ステップ 2: 初期ビューの確認
新しく作成されたプロジェクトを実行すると、下の画像に示すように、ブラウザーに既定のテンプレートが表示されます。
ステップ 3: Aspose.Cells.GridWeb を追加する
- 次の Nuget パッケージをプロジェクトに追加します
- Aspose.Cells.GridWeb パッケージを追加
- Views フォルダーの _ViewImports.cshtml ファイルに以下を追加します。
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
変更後のファイルは次のようになります
- 次のコードを HomeController の Index メソッドに追加します。
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); |
SessionStorePath と ImportExcelFile パスを忘れずに更新してください。
- に次のコードを追加します。インデックス.cshtml 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> |
変更後のファイルは次のようになります。
- Startup.cs ファイルにセッション サポートと GridScheduedService を追加します。
- 次のコード スニペットを ConfigureServices メソッドに追加します。
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>(); |
- 次のコード スニペットを Configure メソッドに追加します。
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?}"); | |
}); |
- 最新の acw_client を次のディレクトリに置きます: wwwroot/js
- 追加AcwControllerコントローラーで、一般的な編集アクションのすべてのデフォルト操作を提供できる acw ルート マップを処理します。
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); | |
} | |
} |
ステップ 4: アプリをテストする
アプリを実行すると、下の画像に示すような出力が得られます。