.NET コアで Aspose.Cells.GridWeb を使用する方法

.NETコアでAspose.Cells.GridWebを使用

このトピックでは、Visual Studio 2019 でサンプル Web サイトを作成して、Aspose.Cells.GridWeb を使用する方法を示します。プロセスはステップに分割されています。

ステップ 1: 新しいプロジェクトの作成

  1. Visual Studio 2019 を開きます。
  2. からファイルメニュー、選択新しい、 それから計画. 新規プロジェクトの作成ダイアログが開きます。
  3. 選択するASP.NET コア Web アプリケーションVisual Studio にインストールされたプロジェクト テンプレートから、.

todo:画像_代替_文章

  1. プロジェクトの場所と名前を指定してクリックします作成.

todo:画像_代替_文章

  1. を選択**Web アプリケーション (Model-View-Controller)**テンプレートを作成し、ASP .NET コア 2.1が選択されます。

todo:画像_代替_文章

  1. クリック作成.

ステップ 2: 初期ビューの確認

新しく作成されたプロジェクトを実行すると、下の画像に示すように、ブラウザーに既定のテンプレートが表示されます。

todo:画像_代替_文章

ステップ 3: Aspose.Cells.GridWeb を追加する

  1. 次の Nuget パッケージをプロジェクトに追加します

  1. Aspose.Cells.GridWeb パッケージを追加

todo:画像_代替_文章

  1. Views フォルダーの _ViewImports.cshtml ファイルに以下を追加します。
    @using Aspose.Cells.GridWeb
    @addTagHelper *, Aspose.Cells.GridWeb

変更後のファイルは次のようになります

todo:画像_代替_文章

  1. 次のコードを HomeController の Index メソッドに追加します。
//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);

todo:画像_代替_文章

  1. に次のコードを追加します。インデックス.cshtml View > Home ディレクトリにあるファイル。
@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>

変更後のファイルは次のようになります。

todo:画像_代替_文章

  1. Startup.cs ファイルにセッション サポートと GridScheduedService を追加します。
  2. 次のコード スニペットを 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>();

todo:画像_代替_文章

  1. 次のコード スニペットを 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?}");
});

todo:画像_代替_文章

  1. 最新の acw_client を次のディレクトリに置きます: wwwroot/js
  2. 追加AcwControllerコントローラーで、一般的な編集アクションのすべてのデフォルト操作を提供できる acw ルート マップを処理します。
public class AcwController : Controller
{
public IActionResult Operation(string type, string id)
{
return Aspose.Cells.GridWeb.AcwController.DoAcwAction(this, type, id);
}
}

todo:画像_代替_文章

ステップ 4: アプリをテストする

アプリを実行すると、下の画像に示すような出力が得られます。

todo:画像_代替_文章