Free Support Forum -

Name of Chart Series if is a formula?

Using aspose.cells, I have a chart series whose name is determined by a formula (it isn’t hard-coded but is dependent on the data on the sheet). Is there an easy way to calculate what this value is? When I use series.Name I just get the formula, which is not what I want.


Well, you can have a series name based on the calculated value of a formula, it works fine.
To get the calculated value of the cell at runtime, you may call Workbook.CalculateFormula() method and then use Cell.StringValue or Cell.Value API to get the calculated value of the formula of source cell.

See the following sample code:
//Suppose Cell C1 has a formula for which we are setting this cell reference for a series name, we need //to get the calculated value of that series.

ASeries aSeries = chart.NSeries[0];
string sname = “=C1”;
string seriesname = sname.Remove(0, 1);
aSeries.Name = sname;
int row, col;
CellsHelper.CellNameToIndex(seriesname,out row, out col);

Thank you.

Thanks, that works great.

It would be nice to have a Workbook.ResolveFormula(…) function, though.