我正在动态创建一些Excel图表数据/系列,无法设置Axis Title字体的颜色/大小。
我可以使用类似下面的代码添加Axis标题:
//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)";
但我无法弄清楚颜色,字体大小,粗体等属性在哪里。
答案 0 :(得分:2)
经过几个小时的观察,我发现了它。
Y1axis.AxisTitle.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = XlRgbColor.rgbDarkRed;
我只需要再挖一点。