zoukankan      html  css  js  c++  java
  • 向工作表添加 Chart 控件

    以编程方式将 Chart 控件添加到工作表中

    image

    • 1.在 Sheet1 的 Startup 事件处理程序中,插入以下代码以添加 Chart 控件。在“Sheet1.cs”文件中的“Sheet1_Startup”事件中运行

      Microsoft.Office.Tools.Excel.Chart employeeData;
      employeeData = this.Controls.AddChart(25, 110, 200, 150, "employees");
      employeeData.ChartType = Excel.XlChartType.xl3DPie;

      // Gets the cells that define the data to be charted.
      Excel.Range chartRange = this.get_Range("A5", "D8");
      employeeData.SetSourceData(chartRange, missing);

    • 2.下面的代码生成一个基于打开的工作表的工作表宿主项,然后添加一个 Chart 控件。在“ThisWorkbook.cs”文件的”ThisWorkbook_Startup”事件中运行。

    • private void AddChart() {

    • // Use the following line of code in projects that target the .NET Framework 4. Worksheet worksheet = Globals.Factory.GetVstoObject( Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet);

    • // In projects that target the .NET Framework 3.5, use the following line of code.

    • // Worksheet worksheet =

    • // ((Excel.Worksheet)Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet).GetVstoObject();

    • Excel.Range cells = worksheet.Range["A5", "D8"];

    • Chart chart = worksheet.Controls.AddChart(cells, "employees");

    • chart.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xl3DPie;

    • chart.SetSourceData(cells, missing);

    • }

  • 相关阅读:
    第24天:Python 标准库概览2
    第23天:Python 标准库概览1
    第22天:Python NameSpace&Scope
    第21天: Web 开发 Jinja2 模板引擎
    第20天:Python 之装饰器
    第19天:Python 之迭代器
    第18天:Python 高阶函数
    第17天:Python 函数之参数
    第16天:Python 错误和异常
    第15天:Python set
  • 原文地址:https://www.cnblogs.com/timy/p/2005473.html
Copyright © 2011-2022 走看看