GridJs Sunucu Tarafı ile Çalışmak

GridJs Sunucu Tarafı ile Çalışmak

1. startup.cs’de ConfigureServices içine servis ekleyin

   services.AddScoped<IGridJsService, GridJsService>();

2. Önbellek Dosyalarını Saklamak İçin Yolu Ayarlayın

Aşağıdaki yolları seçebilirsiniz:

Seçenek 1: GridJsOptions’i Startup.cs’de ConfigureServices içinde ayarlayın

   services.Configure<GridJsOptions>(options =>
	{
		options.FileCacheDirectory = TestConfig.TempDir;
	});

Seçenek 2: Statik Özelliği Doğrudan Ayarlayın

   Config.FileCacheDirectory = TestConfig.TempDir;

Seçenek 3: GridCacheForStream’i Uygulayarak Kendi Önbellek Saklama Kurallarınızı Tanımlayın

Yerel dosya depolama için burada bir örnek:

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;
}
}

Sunucu tarafı depolama için, bir örnek de sunuyoruz. Lütfen kontrol edin:

https://github.com/aspose-cells/Aspose.Cells-for-.NET/blob/master/Examples_GridJs/Models/AwsCache.cs

Depolama hakkında daha fazla detay için, lütfen bu kılavuza bakın

3. Kontrolcü Eylemlerini Uygula

1. GridJsControllerBase’yi Uzatan Bir Kontrolcü Oluşturun

public class GridJs2Controller : GridJsControllerBase

2. Eylemde JSON alın

Eyleminizde JSON verisi almak için iki yöntem vardır:

Seçenek 1: GridJsWorkbook kullanma

GridJsWorkbook wbj = new GridJsWorkbook();
Workbook wb = new Workbook(fullFilePath); 
wbj.ImportExcelFile(wb);
String ret =wbj.ExportToJson(fileName);

Seçenek 2: GridJsControllerBase’de IGridJsService kullanma

 String uid= GridJsWorkbook.GetUidForFile(fileName)
 StringBuilder ret= _gridJsService.DetailFileJsonWithUid(fullFilePath, uid);

Detaylı bilgiler için buradaki örneği kontrol edebilirsiniz: https://github.com/aspose-cells/Aspose.Cells-for-.NET/tree/master/Examples_GridJs