向Excel文档中嵌入VBA控件和UserForm并显示(3)
objCommandButton.Caption = "Hello World"
End Sub
End Class
C#:
[csharp]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using VBE = Microsoft.Vbe.Interop;
using Forms = Microsoft.Vbe.Interop.Forms;
using Excel = Microsoft.Office.Interop.Excel;
namespace ExcelAddIn16
{
public partial class Ribbon1
{
private Forms.CommandButton objCommandButton = null;
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Excel.Application objApplication = Globals.ThisAddIn.Application;
Excel.Workbook objWorkbook = objApplication.ActiveWorkbook;
Excel.Worksheet objWorksheet = objWorkbook.ActiveSheet;
Excel.Shape objShape = objWorksheet.Shapes
.AddOLEObject("Forms.CommandButton.1");
objShape.Name = "btn1";
Excel.OLEObject objOLEObject = objWorksheet.OLEObjects("btn1");
string strModuleString = string.Empty;
if (objOLEObject.Object is Forms.CommandButton)
{
objCommandButton =
(Forms.CommandButton)objOLEObject.Object;
objCommandButton.Caption = "Embedded Button";
objCommandButton.Click +=
相关新闻>>
- asp.net导出Excel方法总结
- DataTable导出到Excel时身份证号信息自动转换为科学计数法的解决
- asp.net中操作excel等不存在类型或命名空间名称Office
- 使用VSTO向Word文档中添加数学公式
- 连接Excel数据源并查询
- 用OpenXml在文档的尾部添加一个Rich Text Content Control/Plain
- 用OpenXml在文档的尾部添加一个Rich Text Content Control/Plain
- ASP.NET 显示 Excel 文件的分页方法
- 两种方法接口aspx页面的编写(页面展示xml文档)
- ASP.NET MVC 将IList<T>导出Excel文档的泛型类(继承自Action
- 发表评论
-
- 最新评论 更多>>