VSTO外接程序项目只用1个文件实现Ribbon CustomUI和CustomTaskpane定制【C#版】
VSTO中的自定义功能区和自定义任务窗格需要用到各种命名空间、添加所需文件,才能实现。后来我发现可以把所有代码都写在ThisAddin.cs这个默认文件中。
大家可以在Visual Studio中创建一个外接程序项目,然后把ThisAddin.cs中的代码整体替换为下面我贴的这个代码。然后启动调试,就可以看到自定义功能区和任务窗格了。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Excel; namespace ExcelAddInTemplate_CS
{
public partial class ThisAddIn
{
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Module1.CreateCTP();
} private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
Module1.DisposeCTP();
}
protected override Office.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
return new Ribbon1();
}
#region VSTO 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(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
} #endregion
}
[System.Runtime.InteropServices.ComVisible(true)]
public class Ribbon1:Microsoft.Office.Core.IRibbonExtensibility
{
public Office.IRibbonUI R;
string Office.IRibbonExtensibility.GetCustomUI(string RibbonID)
{
string xml= @"<customUI xmlns='http://schemas.microsoft.com/office/2009/07/customui' onLoad='OnLoad'>
<ribbon startFromScratch='false'>
<tabs>
<tab id='Tab1' label='RibbonXmlEditor'>
<group id='Group1' label='Author:ryueifu'>
<button id='Button1' label='CTP' imageMso='C' onAction='Button1_Click'/>
<button id='Button2' label='UnLoad' imageMso='U' onAction='Button2_Click'/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>";
return xml;
}
public void OnLoad(Office.IRibbonUI ribbon)
{
R = ribbon;
R.ActivateTab(ControlID: "Tab1");
}
public void Button1_Click(Office.IRibbonControl control)
{
Module1.ctp.Visible = !Module1.ctp.Visible;
}
public void Button2_Click(Office.IRibbonControl control)
{
Office.COMAddIn ThisCOM = Globals.ThisAddIn.Application.COMAddIns.Item("ExcelAddInTemplate_CS");
ThisCOM.Connect = false;
} }
public static class Module1
{
public static System.Windows.Forms.UserControl uc;
public static Microsoft.Office.Tools.CustomTaskPane ctp;
public static void CreateCTP()
{
uc = new System.Windows.Forms.UserControl();
ctp = Globals.ThisAddIn.CustomTaskPanes.Add(control: uc, title: "CTP");
ctp.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionRight;
ctp.Visible = true;
}
public static void DisposeCTP()
{
ctp.Dispose();
}
}
}
VSTO外接程序项目只用1个文件实现Ribbon CustomUI和CustomTaskpane定制【C#版】的更多相关文章
- VSTO外接程序项目只用1个文件实现Ribbon CustomUI和CustomTaskpane定制【VB.Net版】
VSTO中的自定义功能区和自定义任务窗格需要用到各种命名空间.添加所需文件,才能实现.后来我发现可以把所有代码都写在ThisAddin.vb这个默认文件中. 大家可以在Visual Studio中创建 ...
- Excel-DNA项目只用1个文件实现Ribbon CustomUI和CustomTaskpane定制【C#版】
Excel-DNA项目中的自定义功能区和自定义任务窗格需要用到各种命名空间.添加所需文件,才能实现.后来我发现可以把所有代码都写在Class1.cs这个默认文件中. 大家可以在Visual Studi ...
- Excel-DNA项目只用1个文件实现Ribbon CustomUI和CustomTaskpane定制【VB.Net版】
Excel-DNA项目中的自定义功能区和自定义任务窗格需要用到各种命名空间.添加所需文件,才能实现.后来我发现可以把所有代码都写在Class1.vb这个默认文件中. 大家可以在Visual Studi ...
- Web 应用程序项目与 Visual Studio 中的网站项目的异同
要查看英语原文,请勾选“英语”复选框.也可将鼠标指针移到文本上,在弹出窗口中显示英语原文. 翻译 英语 本文档已存档,并且将不进行维护. Web 应用程序项目与 Visual Studio 中的网站项 ...
- MFC:“Debug Assertion Failed!” ——自动生成的单文档程序项目编译运行就有错误
今天照着孙鑫老师的VC++教程学习文件的操作,VS2010,单文档应用程序,项目文件命名为File,也就有了自动生成的CFileDoc.CFileView等类,一进去就编译运行(就是最初自动生成的项目 ...
- 使用 Visual C# .NET 生成 Office COM 外接程序
Microsoft Office XP 和 Microsoft Office 2003 都支持一种新的统一的设计结构,这种结构用于生成应用程序外接程序以增强和控制 Office 应用程序.这些外接程序 ...
- 【微信小程序项目实践总结】30分钟从陌生到熟悉 web app 、native app、hybrid app比较 30分钟ES6从陌生到熟悉 【原创】浅谈内存泄露 HTML5 五子棋 - JS/Canvas 游戏 meta 详解,html5 meta 标签日常设置 C#中回滚TransactionScope的使用方法和原理
[微信小程序项目实践总结]30分钟从陌生到熟悉 前言 我们之前对小程序做了基本学习: 1. 微信小程序开发07-列表页面怎么做 2. 微信小程序开发06-一个业务页面的完成 3. 微信小程序开发05- ...
- (转) VS2010 Addins 外接程序(插件)开发
http://www.cnblogs.com/Leo_wl/archive/2013/03/21/2973886.html VS2010 Addins 外接程序(插件)开发 阅读目录 VS2010 A ...
- 【VS外接程序】利用T4模板生成模块代码
引言 记得第一次做asp.net mvc项目时,可以用model直接生成Html的增删改查页面, 没什么特殊要求都可以不用修改直接用了, 觉得很神奇,效率太高了.后来在做客户端开发时,发现很多模块都是 ...
随机推荐
- XML文件读写编码不是UTF-8的问题
FileWriter和FileReader在写.读文件时,使用系统当前默认的编码方式. 在中文win下encoding基本是GB2312,在英文win下基本是ISO-8859-1.所以要创建一个UTF ...
- LeetCode 543. Diameter of Binary Tree 二叉树的直径 (C++/Java)
题目: Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of ...
- i春秋-web-爆破-1
题目内容:flag就在某六位变量中. 题目 include "flag.php"; $a = @$_REQUEST['hello']; if(!preg_match('/^\w*$ ...
- pcl 1.8 + VS 2010 在win7 x64下的配置
https://blog.csdn.net/zhangping560/article/details/53978011 版权声明:(转载请注明作者和出处:http://blog.csdn.net/zh ...
- MySQL--SHOW ENGINE INNODB STATUS
===================================== -- :: 0x7f305b965700 INNODB MONITOR OUTPUT =================== ...
- Python笔记_第四篇_高阶编程_正则表达式_3.正则表达式深入
1. re.split 正则的字符串切割 str1 = "Thomas is a good man" print(re.split(r" +",str1)) # ...
- 65)STL中string的知识
1)代码展示: string是一个类,只不过封装了 char* 而且还封装了 很多的字符串操作函数 2)string类的初始化: string的构造函数 ² 默认构造函数: string(); ...
- c#之初识结构(Struct)
C# 结构(Struct) 首先结构是值类型数据结构.它使得一个单一变量可以存储各种数据类型的相关数据.struct 关键字用于创建结构.通俗说:结构就是一个可以包含不同数据类型的集合.它是一种可以自 ...
- 第二季第十天 es6新特性新特性
1.set的应用(去重)js标准内置对象 适用范围:String,Array(数字基本数据类型不可以) set的方法:例子 var s = new Set(data) 增加: s.add(data) ...
- ZJNU 1196 - 三阶魔方【模拟题】——高级
大模拟,空想很容易把面和面之间的关系搞混 所以这时候需要自己找一个正方体(实在不行长方体代替)跟着图把每个面正方向标出来 然后模拟6种操作分别会对哪些块进行操作 对于储存数据的想法是,对输入输出进行分 ...