Working with GridJs Server Side

Working with GridJs Server Side

1. Add service in ConfigureServices in Startup.cs

services.AddScoped<IGridJsService, GridJsService>();

2. Set the Path to Store Cache Files

You can choose any of the following ways:

Option 1: Set GridJsOptions in ConfigureServices in Startup.cs

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

Option 2: Directly set the static property

Config.FileCacheDirectory = TestConfig.TempDir;

Option 3: Define your own cache storage rule by implementing GridCacheForStream

For local file storage, here is an example:

For server‑side storage, we also provide an example. Please check:

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

For more details about storage, please refer to this guide

3. Implement Controller Actions

1. Create a controller that extends GridJsControllerBase

public class GridJs2Controller : GridJsControllerBase

2. Get JSON in action

There are two ways to get JSON data in your action:

Option 1: Using GridJsWorkbook

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

Option 2: Using IGridJsService in GridJsControllerBase

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

For detailed info, you can check the example here:

https://github.com/aspose-cells/Aspose.Cells.Grid-for-.NET/tree/master/Examples_GridJs