كيفية استخدام Aspose.Cells.GridWeb مع .NET Core

استخدام Aspose.Cells.GridWeb مع .NET Core

يوضح هذا الموضوع كيفية استخدام Aspose.Cells.GridWeb عن طريق إنشاء موقع ويب عيني في Visual Studio 2019. تم تقسيم العملية إلى خطوات.

الخطوة 1: إنشاء مشروع جديد

  1. قم بفتح برنامج Visual Studio 2019.
  2. من قائمة ملف, حدد جديد, ثم مشروع. يتم فتح مربع حوار إنشاء مشروع جديد.
  3. حدد ASP.NET Core Web Application من قوالب المشاريع المثبتة في برنامج Visual Studio وانقر التالي.

todo:image_alt_text

  1. حدد الموقع واسم المشروع ثم انقر إنشاء.

todo:image_alt_text

  1. حدد قالب Web Application (Model-View-Controller) وتأكد من تحديد ASP .NET Core 2.1.

todo:image_alt_text

  1. انقر إنشاء.

الخطوة 2: فحص العرض الأولي

تشغيل المشروع الذي تم إنشاؤه مؤخرًا يعرض النموذج الافتراضي في المتصفح كما هو موضح في الصورة أدناه.

todo:image_alt_text

الخطوة 3: إضافة Aspose.Cells.GridWeb

  1. أضف حزم Nuget التالية إلى المشروع.

  1. أضف حزمة Aspose.Cells.GridWeb

todo:image_alt_text

  1. أضف الكود التالي إلى ملف _ViewImports.cshtml في مجلدات العرض.
    @using Aspose.Cells.GridWeb
    @addTagHelper *, Aspose.Cells.GridWeb

سيبدو الملف بهذا الشكل بعد التعديلات

todo:image_alt_text

  1. ضع الكود التالي في طريقة 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);

todo:image_alt_text

  1. أضف الكود التالي في ملف 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>

سيبدو الملف بهذا الشكل بعد التغيير.

todo:image_alt_text

  1. أضف دعم الجلسة و GridScheduedService في ملف Startup.cs
    1. أضف كود المقتطف التالي في طريقة الـ 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>();

todo:image_alt_text

  1. أضف قطعة الكود التالية في طريقة التكوين.
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:image_alt_text

  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:image_alt_text

الخطوة 4: اختبار التطبيق

تشغيل التطبيق سيكون المخرج مشابهًا لما هو موضح في الصورة أدناه.

todo:image_alt_text