كيفية استخدام Aspose.Cells.GridWeb مع .NET Core
Contents
[
Hide
]
يشرح هذا الموضوع كيفية استخدام Aspose.Cells.GridWeb مع تطبيقات .NET Core باستخدام Visual Studio.NET 2019. هذا الموضوع مفيد للمطورين على مستوى المبتدئين الذين يعملون مع Aspose.Cells.GridWeb.
استخدم Aspose.Cells.GridWeb مع .NET Core
يوضح هذا الموضوع كيفية استخدام Aspose.Cells.GridWeb من خلال إنشاء نموذج لموقع ويب في Visual Studio 2019. وقد تم تقسيم العملية إلى خطوات.
الخطوة الأولى: إنشاء مشروع جديد
- افتح Visual Studio 2019.
- منملف القائمة ، حددجديد ، ومن بعدمشروع. يتم فتح مربع حوار إنشاء مشروع جديد.
- يختارASP.NET تطبيق الويب الأساسي من Visual Studio تثبيت قوالب المشروع وانقر فوقالتالي.
- حدد موقعًا حيث موقع واسم المشروع وانقرخلق.
- حدد ملفتطبيق الويب (Model-View-Controller) وتأكد من ذلكASP .NET Core 2.1.2 تحديث تم الإختيار.
- انقرخلق.
الخطوة 2: فحص العرض الأولي
يؤدي تشغيل المشروع الذي تم إنشاؤه حديثًا إلى إظهار القالب الافتراضي في المتصفح كما هو موضح في الصورة أدناه.
الخطوة 3: إضافة Aspose.Cells.GridWeb
- أضف الحزم Nuget التالية إلى المشروع
- إضافة Aspose.Cells.GridWeb Package
- أضف ما يلي إلى ملف ** _ ViewImports.cshtml ** في مجلد Views.
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’s.
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.
- أضف التعليمات البرمجية التالية في ملفIndex.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
@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
- قم بإضافة مقتطف الشفرة التالي في طريقة 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>(); |
- أضف مقتطف الشفرة التالي في طريقة التكوين.
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: اختبر التطبيق
سيؤدي تشغيل التطبيق إلى إخراج مشابه لما هو موضح في الصورة أدناه.