Visual Studio 2008 による the 2007 Microsoft Office sysrem 開発概要

スクリーンキャスト

このデモでは、Visual Studio 2008 (旧称:Visual Studio Codename “Orcas”) の Beta 2 を使用しています。このデモで使用されているクラス、メソッドなどについては今後変更される可能性がありますのでご注意ください。

このデモの内容

ここでは、Visual Studio 2008 に実装された VSTO (Visual Studio tools for the 2007 Microsoft Office system) を使用した、アプリケーションレベルのアドインと、ドキュメントレベルのアプリケーションの開発手法をご紹介します。

デモでご紹介しているソースコード

【アプリケーションレベルのアドイン (ThisAddin.cs)】

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;

namespace Demo_AppLv
{
    public partial class ThisAddIn
    {

        public UserControl1 myControl;
        public Microsoft.Office.Tools.CustomTaskPane myTaskPane;

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {

            myControl = new UserControl1();
            myTaskPane = this.CustomTaskPanes.Add(myControl, "カレンダー");
            myTaskPane.Visible = false;
        
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO で生成されたコード

        /// <summary>
        /// デザイナ サポートに必要なメソッドです。このメソッドの内容を
        /// コード エディタで変更しないでください。
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }
}

【アプリケーションレベルのアドイン (UserContorol1.cs)】

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;

namespace Demo_AppLv
{
    public partial class UserControl1 : UserControl
    {
        public UserControl1()
        {
            InitializeComponent();
        }

        private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
        {

            Excel.Range range = (Excel.Range)Globals.ThisAddIn.Application.Selection;
            range.Value2 = monthCalendar1.SelectionRange.Start.ToShortDateString();
         
        }
    }
}

【ドキュメントレベルのアプリケーション (ThisWorkbook.cs)】

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;

namespace ExcelWorkbook1
{
    public partial class ThisWorkbook
    {
        private void ThisWorkbook_Startup(object sender, System.EventArgs e)
        {
            ActionsPaneControl1 myControl = new ActionsPaneControl1();
            this.ActionsPane.Controls.Add(myControl);
            this.ActionsPane.Visible = true;
        }

        private void ThisWorkbook_Shutdown(object sender, System.EventArgs e)
        {
        }

        #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

    }
}

【ドキュメントレベルのアプリケーション (ActionsPaneControl1.cs)】

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Office = Microsoft.Office.Core;

namespace ExcelWorkbook1
{
    partial class ActionsPaneControl1 : UserControl
    {
        public ActionsPaneControl1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Byte level = Convert.ToByte(textBox1.Text);
                Globals.Sheet1.jobsTableAdapter.FillByLevel(Globals.Sheet1.pubsDataSet.jobs, level);
        }
    }
}

![](images/cc707258.top(ja-jp, MSDN.10).gif)ページのトップへ