Search code examples
c#excelgembox-spreadsheet

R1C1-formulas in Gembox.Spreadsheet


I am testing GemBox.Spreadsheet (47.0.1031) and found a note that R1C1-formulas are available in the latest versions.

But, how does it work? My tests have failed so far:

SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
var f = new ExcelFile();
var ws = f.Worksheets.Add("Sheet1");
f.CalculationOptions.PrioritizeR1C1ReferencingNotation = true;

for(int i = 0; i<50; i++)
{
    ws.Cells[i, 0].Value = i + 1;
    ws.Cells[i, 1].Formula = "=RC[-1] * 17";
}
f.Save(..path..);

not even =R1C1 works, and =RC1 is read as an absolute reference (column RC row 1), despite my attempt with the PrioritizeR1C1ReferencingNotation setting.

Excel shows a warning about corrupted content in /xl/worksheets/sheet1.xml-Part when opening the file and removes the formula.


Solution

  • Previously, the R1C1 notation was only supported by the calculation engine.
    Nevertheless, please try using the current latest bugfix version or NuGet package.

    And try the following:

    var ef = new ExcelFile();
    var ws = ef.Worksheets.Add("Sheet1");
    
    for (int i = 0; i < 50; i++)
    {
        ws.Cells[i, 0].Value = i + 1;
        ws.Cells[i, 1].FormulaR1C1 = "=RC[-1] * 17";
    }
    
    ef.Save("output.xlsx");