ChartSheet.SetElement 方法

修改 ChartSheet 中显示的图表的元素。

命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel(在 Microsoft.Office.Tools.Excel.dll 中)

语法

声明
Sub SetElement ( _
    Element As MsoChartElementType _
)
void SetElement(
    MsoChartElementType Element
)

参数

备注

使用 SetElement 方法可以根据 Microsoft.Office.Core.MsoChartElementType 值所指定的选项修改图表的元素。 例如,若要隐藏表格图例,可将值 Microsoft.Office.Core.MsoChartElementType.msoElementLegendNone 传递给 SetElement 方法。

使用此方法可以执行的操作与选择图表后功能区上**“布局”**选项卡上的下列按钮相对应:

  • **“标签”**组中的所有按钮。

  • **“坐标轴”**组中的所有按钮。

  • **“分析”**组中的所有按钮。

  • “背景”组中的“绘图区”、**“背景墙”“图表基底”**按钮。

示例

下面的代码示例应用可供图表工作表 Chart1 中图表的图表类型使用的第 10 个布局。 此外,该示例还使用 SetElement 方法应用更多布局更改:将图表标题的样式设置为居中且位于图表网格区域内,为水平轴添加标题,并且为垂直轴添加旋转标题。 若要运行此代码示例,工作簿必须包含一个名为 Chart1 的二维簇状柱形图表工作表。

Private Sub DesignChartSheet()
    Dim myChartSheet As Microsoft.Office.Tools.Excel.ChartSheet = _
        Globals.Chart1.Base

    myChartSheet.ApplyLayout(10)

    myChartSheet.SetElement(Microsoft.Office.Core.MsoChartElementType. _
                       msoElementChartTitleCenteredOverlay)
    myChartSheet.SetElement(Microsoft.Office.Core.MsoChartElementType. _
                       msoElementPrimaryCategoryAxisTitleHorizontal)
    myChartSheet.SetElement(Microsoft.Office.Core.MsoChartElementType. _
                       msoElementPrimaryValueAxisTitleRotated)
End Sub
private void DesignChartSheet()
{
    Microsoft.Office.Tools.Excel.ChartSheet myChartSheet  =
        Globals.Chart1.Base;

    myChartSheet.ApplyLayout(10, myChartSheet.ChartType);

    myChartSheet.SetElement(Microsoft.Office.Core.MsoChartElementType.
                       msoElementChartTitleCenteredOverlay);
    myChartSheet.SetElement(Microsoft.Office.Core.MsoChartElementType.
                       msoElementPrimaryCategoryAxisTitleHorizontal);
    myChartSheet.SetElement(Microsoft.Office.Core.MsoChartElementType.
                       msoElementPrimaryValueAxisTitleRotated);
}

.NET Framework 安全性

请参见

参考

ChartSheet 接口

Microsoft.Office.Tools.Excel 命名空间