GridJs サーバー側での作業
Contents
[
Hide
]
GridJs サーバー側での作業
1. GridCacheForStream を実装する
ローカル ファイル ストレージの例を次に示します。
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
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
2. スプレッドシート ファイルから json を取得します。
GridJsWorkbook wbj = new GridJsWorkbook();
using (FileStream fs = new FileStream(path, FileMode.Open))
{
wbj.ImportExcelFile(fs,GridJsWorkbook.GetGridLoadFormat(Path.GetExtension(path)));
}
String ret =wbj.ExportToJson();
3. スプレッドシート ファイルから画像/形状を取得する
//Gridjs will automatically zip all the images/shapes into a zip stream and store it in cache using the cache implemention.
//GridJsWorkbook.CacheImp.SaveStream(zipoutStream, fileid);
//get the fileid in the cache,uid is the unique id for the spreadsheet instance, sheetid is the sheet index,
String fileid=(uniqueid + "." + (sheetid + '_batch.zip'))
//get the zip file stream by the fileid
Stream s=GridJsWorkbook.CacheImp.LoadStream(fileid), mimeType, fileid.Replace('/', '.')
4. キャッシュ内のスプレッドシート ファイルを更新する
GridJsWorkbook gwb = new GridJsWorkbook();
//p is the update json,uid is the unique id for the spreadsheet
String ret = gwb.UpdateCell(p, uid);
5. スプレッドシート ファイルをキャッシュに保存する
GridJsWorkbook wb = new GridJsWorkbook();
//p is the update json,uid is the unique id for the spreadsheet
wb.MergeExcelFileFromJson(uid, p);
wb.SaveToCacheWithFileName(uid, filename,password);
詳細情報については、ここで例を確認できます。 https://github.com/aspose-cells/Aspose.Cells-for-.NET/tree/master/Examples_GridJs