将Excel嵌入Word

时间:2018-10-26 09:53:44

标签: c# excel interop vsto

当前,我正在使用Excel加载项,用户可以在其中选择XML文件。我阅读了XML并将节点添加到TreeView。该TreeView放置在任务窗格中。单独启动Excel时,一切正常,但是当我在Word中添加图表或嵌入式Excel并在Excel中打开它时,“任务窗格”没有显示。

此代码最终触发打开TaskPane的事件

private void ShowTaskPane_TglBtn_Click(object sender, RibbonControlEventArgs e)
{
      Globals.ThisAddIn.TaskPane.Visible = ((RibbonToggleButton)sender).Checked;
}

此代码将真正打开任务窗格:

public partial class ThisAddIn
{
    public UserControl1 taskPaneControl1;
    private Microsoft.Office.Tools.CustomTaskPane taskPaneValue;

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        taskPaneControl1 = new UserControl1();
        taskPaneValue = this.CustomTaskPanes.Add(taskPaneControl1, "Task Pane");
        taskPaneValue.VisibleChanged += new EventHandler(taskPaneValue_VisibleChanged);
    }

    private void taskPaneValue_VisibleChanged(object sender, System.EventArgs e)
    {
        Globals.Ribbons.Ribbon1.ShowTaskPane_TglBtn.Checked =
            taskPaneValue.Visible;
    }

    public Microsoft.Office.Tools.CustomTaskPane TaskPane
    {
        get
        {
            return taskPaneValue;
        }
    }
}

0 个答案:

没有答案