在Excel中设置Excel图表轴标题颜色和大小
我dynamic地创build一些Excel图表数据/系列,不能设置轴标题字体颜色/大小。
我能够添加与以下代码类似的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)";
但我无法弄清楚颜色,字体大小,粗体等属性。
几个小时后,我发现它。
Y1axis.AxisTitle.Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = XlRgbColor.rgbDarkRed;
我不得不再挖掘一点。