العمل مع الخادم الجانبي لـ GridJs
العمل مع الخادم الجانبي لـ GridJs
1. أضف خدمة في ConfigureServices في startup.cs
services.AddScoped<IGridJsService, GridJsService>();
2. تعيين مسار تخزين ملفات التخزين المؤقتة
يمكنك اختيار أي من الطرق التالية:
الخيار 1: تعيين GridJsOptions في ConfigureServices في Startup.cs
services.Configure<GridJsOptions>(options =>
{
options.FileCacheDirectory = TestConfig.TempDir;
});
الخيار 2: تعيين الخاصية الثابتة مباشرة
Config.FileCacheDirectory = TestConfig.TempDir;
الخيار 3: تحديد قاعدة تخزين ذاكرة التخزين المؤقت الخاصة بك من خلال تنفيذ GridCacheForStream
بالنسبة لتخزين الملفات المحلي ، إليك مثال:
public class LocalFileCache : GridCacheForStream | |
{ | |
public LocalFileCache() | |
{ | |
string streampath = Path.Combine(Config.FileCacheDirectory, "streamcache"); | |
if (!Directory.Exists(streampath)) | |
{ | |
//create cache directory if not exists | |
Directory.CreateDirectory(streampath); | |
} | |
} | |
/// <summary> | |
/// Implement this method to savecache,save the stream to the cache object with the key id. | |
/// </summary> | |
/// <param name="s">the source stream </param> | |
/// <param name="uid">he key id.</param> | |
public override void SaveStream(Stream s, String uid) | |
{ | |
String filepath = Path.Combine(Config.FileCacheDirectory + Path.DirectorySeparatorChar + "streamcache", uid.Replace('/', '.')); | |
using (FileStream fs = new FileStream(filepath, FileMode.Create)) | |
{ | |
s.Position = 0; | |
s.CopyTo(fs); | |
} | |
} | |
/// <summary> | |
/// Implement this method to loadcache with the key uid,return the stream from the cache object. | |
/// </summary> | |
/// <param name="uid">the key id</param> | |
/// <returns>the stream from the cache</returns> | |
public override Stream LoadStream(String uid) | |
{ | |
String filepath = Path.Combine(Config.FileCacheDirectory + Path.DirectorySeparatorChar + "streamcache", uid.Replace('/', '.')); | |
FileStream fs = new FileStream(filepath, FileMode.Open); | |
return fs; | |
} | |
/// <summary> | |
/// implement the url in action controller to get the file | |
/// </summary> | |
/// <param name="uid">the key id</param> | |
/// <returns></returns> | |
public override String GetFileUrl(string uid) | |
{ | |
return "/GridJs2/GetFile?id=" + uid; | |
} | |
} |
بالنسبة للتخزين في جانب الخادم، نوفر أيضًا مثالًا. يرجى التحقق من:
https://github.com/aspose-cells/Aspose.Cells-for-.NET/blob/master/Examples_GridJs/Models/AwsCache.cs
لمزيد من التفاصيل حول التخزين، يرجى الرجوع إلى الدليل
3. تنفيذ إجراءات وحدة التحكم
1. إنشاء وحدة تحكم تمتد من GridJsControllerBase
public class GridJs2Controller : GridJsControllerBase
2 الحصول على JSON في الإجراء
هناك طريقتان للحصول على بيانات JSON في الإجراء الخاص بك:
الخيار 1: باستخدام GridJsWorkbook
GridJsWorkbook wbj = new GridJsWorkbook();
Workbook wb = new Workbook(fullFilePath);
wbj.ImportExcelFile(wb);
String ret =wbj.ExportToJson(fileName);
الخيار 2: باستخدام IGridJsService في GridJsControllerBase
String uid= GridJsWorkbook.GetUidForFile(fileName)
StringBuilder ret= _gridJsService.DetailFileJsonWithUid(fullFilePath, uid);
للحصول على معلومات مفصلة ، يمكنك التحقق من المثال هنا: https://github.com/aspose-cells/Aspose.Cells-for-.NET/tree/master/Examples_GridJs