如何在我的另一个.NET应用程序中使用VSTO项目DLL for excel

时间:2015-02-28 09:28:28

标签: .net visual-studio-2010 c#-4.0 office-interop

我使用Visual Studio 2010办公模板(适用于excel 2007)创建了一个项目。它的工作正常。我在ThisWorkbook_Startup()方法中执行我的计算,该方法正在Startup事件中使用,定义为

    #region VSTO Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InternalStartup()
    {
        this.Startup += new System.EventHandler(ThisWorkbook_Startup);
        this.Shutdown += new System.EventHandler(ThisWorkbook_Shutdown);

    }

    #endregion  

我正在使用Global.Sheet1,Global.Sheet2和Global.Sheet3在excel模板中写入数据并将其传递给我的自定义方法WriteExcel(Globals.Sheet1,Globals.Sheet2,Globals.Sheet3);

我想在我的另一个.net项目中使用这个dll,而我这样做的初始化Globals.Sheet1,Globals.Sheet2,Globals.Sheet3属性为null,这是不期望的。 如何在全局属性上获取命令以使用定义的模板打开和写入数据。

1 个答案:

答案 0 :(得分:0)

您需要使用Excel对象模型方法和属性。 VSTO加载项之外没有Global类(仅属于VSTO运行时)。

看起来您需要从其他应用程序自动化Excel。有关详细信息,请参阅How to automate Microsoft Excel from Microsoft Visual C#.NET

例如,您可以在WorkbookApplications类中找到Worksheets属性。

相关问题