Question

I am dynamically creating some Excel Chart datas/series and cannot set the Axis Title font color/size.

I am able to add the Axis Titles with code similar to below:

//Gets the WorkSheet and ChartObject
Worksheet DataSheet = (Worksheet)Template.Worksheets[1];
Chart Graph = (DataSheet.ChartObjects(1) as ChartObject).Chart;

//Gets the Axes
Axis Xaxis = Graph.Axes(XlAxisType.xlCategory, XlAxisGroup.xlPrimary) as Axis;
Axis Y1axis = Graph.Axes(XlAxisType.xlValue, XlAxisGroup.xlPrimary) as Axis;
Axis Y2axis = Graph.Axes(XlAxisType.xlValue, XlAxisGroup.xlSecondary) as Axis;

//Sets X-axis attributes
Xaxis.TickLabels.Font.Size = 8;
Xaxis.HasTitle = true;
Xaxis.AxisTitle.Text = "Current (A)";

//Sets Y-Primary Axis attributes
Y1axis.TickLabels.Font.Size = 8;
Y1axis.HasTitle = true;
Y1axis.AxisTitle.Text = "Power (W)";

//Sets Y-Secondary Axis attributes
Y2axis.TickLabels.Font.Size = 8;
Y2axis.HasTitle = true;
Y2axis.AxisTitle.Text = "Voltage (V)";

But I can't figure out where the color, font size, bold, etc... attributes are.

Was it helpful?

Solution

I found it after a few more hours of looking.

Y1axis.AxisTitle.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = XlRgbColor.rgbDarkRed;

I just had to dig a bit farther.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top