كيفية استخدام Aspose.Cells.GridWeb مع .NET Core
استخدام Aspose.Cells.GridWeb مع .NET Core
يوضح هذا الموضوع كيفية استخدام Aspose.Cells.GridWeb عن طريق إنشاء موقع ويب عيني في Visual Studio 2019. تم تقسيم العملية إلى خطوات.
الخطوة 1: إنشاء مشروع جديد
- قم بفتح برنامج Visual Studio 2019.
- من قائمة ملف, حدد جديد, ثم مشروع. يتم فتح مربع حوار إنشاء مشروع جديد.
- حدد ASP.NET Core Web Application من قوالب المشاريع المثبتة في برنامج Visual Studio وانقر التالي.
- حدد الموقع واسم المشروع ثم انقر إنشاء.
- حدد قالب Web Application (Model-View-Controller) وتأكد من تحديد ASP .NET Core 2.1.
- انقر إنشاء.
الخطوة 2: فحص العرض الأولي
تشغيل المشروع الذي تم إنشاؤه مؤخرًا يعرض النموذج الافتراضي في المتصفح كما هو موضح في الصورة أدناه.
الخطوة 3: إضافة Aspose.Cells.GridWeb
- أضف حزم Nuget التالية إلى المشروع.
- أضف حزمة Aspose.Cells.GridWeb
- أضف الكود التالي إلى ملف _ViewImports.cshtml في مجلدات العرض.
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
سيبدو الملف بهذا الشكل بعد التعديلات
- ضع الكود التالي في طريقة Index في ملف HomeController.
//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); |
- أضف الكود التالي في ملف Index.cshtml في مجلد العرض > الرئيسي.
@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> |
سيبدو الملف بهذا الشكل بعد التغيير.
- أضف دعم الجلسة و GridScheduedService في ملف Startup.cs
- أضف كود المقتطف التالي في طريقة الـ ConfigureService.
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>(); |
- أضف قطعة الكود التالية في طريقة التكوين.
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 التي يمكن أن توفر جميع العمليات الافتراضية لإجراءات تحرير عامة.
public class AcwController : Controller | |
{ | |
public IActionResult Operation(string type, string id) | |
{ | |
return Aspose.Cells.GridWeb.AcwController.DoAcwAction(this, type, id); | |
} | |
} |
الخطوة 4: اختبار التطبيق
تشغيل التطبيق سيكون المخرج مشابهًا لما هو موضح في الصورة أدناه.