Skip to content

Instantly share code, notes, and snippets.

@aspose-cells-gists
Last active March 17, 2025 09:12
Show Gist options
  • Select an option

  • Save aspose-cells-gists/fb32f5c7a98978432e5e05c50995a4ca to your computer and use it in GitHub Desktop.

Select an option

Save aspose-cells-gists/fb32f5c7a98978432e5e05c50995a4ca to your computer and use it in GitHub Desktop.
Aspose.Cells.GridJs for .NET
This Gist contains code example snippets for Aspose.Cells.GridJs for .NET.
class MyCalculation : GridAbstractCalculationEngine
{
public override void Calculate(GridCalculationData data)
{
if (!"MYTESTFUNC".Equals(data.FunctionName.ToUpper()))
{
return;
}
data.CalculatedValue = (decimal)(2.0 * (double)data.GetParamValue(0));
}
}
// in the startup.cs when you do initialization ,set the CalculateEngine
MyCalculation ce = new MyCalculation();
GridJsWorkbook.CalculateEngine = ce;
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment