基于Visual Studio2010开发office2010办公自动化应用(7)自定义ExcelWorkbook

基于Visual Studio2010开发office2010办公自动化应用(7)自定义ExcelWorkbook_第1张图片

ExcelWorkbook是office电子文档自定义工作薄,能让Excel2010 与程序智能地交互,我们可以在WordTemplate里面添加我们任何想要添加的功能程序。

基于Visual Studio2010开发office2010办公自动化应用(7)自定义ExcelWorkbook_第2张图片

我们来实践一个在Excel2010 里面插入一个简单浏览器的功能,比如我们的Excel文档需要上网的功能,这点在现代办公中是非常有意义的。

启动VS2010

基于Visual Studio2010开发office2010办公自动化应用(7)自定义ExcelWorkbook_第3张图片

创建一个ExcelWorkbookCSDN工程

 基于Visual Studio2010开发office2010办公自动化应用(7)自定义ExcelWorkbook_第4张图片

选择创建新模板

 基于Visual Studio2010开发office2010办公自动化应用(7)自定义ExcelWorkbook_第5张图片

创建后进入VS2010程序界面,在ExcelWorkbookCSDN.xlsx中插入一个webbrower,textbox,button,

 基于Visual Studio2010开发office2010办公自动化应用(7)自定义ExcelWorkbook_第6张图片

双击button,插入下列代码

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

namespace ExcelWorkbookCSDN
{
    public partial class Sheet1
    {
        private void Sheet1_Startup(object sender, System.EventArgs e)
        {
          
        }

        private void Sheet1_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.button1.Click += new System.EventHandler(this.button1_Click);
            this.Startup += new System.EventHandler(this.Sheet1_Startup);
            this.Shutdown += new System.EventHandler(this.Sheet1_Shutdown);

        }

        #endregion

        private void button1_Click(object sender, EventArgs e)
        {
            this.webBrowser1.Navigate(this.textBox1.Text);
        }

    }
}

按下F5开始调试

基于Visual Studio2010开发office2010办公自动化应用(7)自定义ExcelWorkbook_第7张图片

 运行后界面如下,Excel文档打开了以后,文档内嵌一个浏览器

 基于Visual Studio2010开发office2010办公自动化应用(7)自定义ExcelWorkbook_第8张图片

点击登录按钮即可观看想要浏览的网页

 基于Visual Studio2010开发office2010办公自动化应用(7)自定义ExcelWorkbook_第9张图片


原文链接: http://blog.csdn.net/yincheng01/article/details/5559123

你可能感兴趣的:(基于Visual Studio2010开发office2010办公自动化应用(7)自定义ExcelWorkbook)