ExcelWorkbook是office电子文档自定义工作薄,能让Excel2010 与程序智能地交互,我们可以在WordTemplate里面添加我们任何想要添加的功能程序。
我们来实践一个在Excel2010 里面插入一个简单浏览器的功能,比如我们的Excel文档需要上网的功能,这点在现代办公中是非常有意义的。
启动VS2010
创建一个ExcelWorkbookCSDN工程
选择创建新模板
创建后进入VS2010程序界面,在ExcelWorkbookCSDN.xlsx中插入一个webbrower,textbox,button,
双击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开始调试
运行后界面如下,Excel文档打开了以后,文档内嵌一个浏览器
点击登录按钮即可观看想要浏览的网页
原文链接: http://blog.csdn.net/yincheng01/article/details/5559123