描述
开 本: 16开纸 张: 胶版纸包 装: 平装-胶订是否套装: 否国际标准书号ISBN: 9787302453710
内容包括VSTO入门概述、C#语法基础、C#进阶技术、C#操作Excel对象、创建Office外接程序、自定义
Office功能区、自定义任务窗格、自定义工具栏,VSTO外接程序的部署分发、VSTO开发Office文档、
VSTO开发资源大全、C#与VB/VBA语言的差异对比。书中所有章节涉及的程序代码都给出了详细的注
释。本书可以让读者轻松熟悉Visual Studio开发环境,跨入C#编程的门槛,掌握VSTO开发的步骤。
本书可作为职场办公人员、高校理工科师生、Office专业开发人员自学用书,也可以作为Office编
程培训讲师的教学参考书。
第1章 VSTO入门概述
················1
1.1 VSTO简述 ·································· 1
1.1.1 VSTO的功能与特点 ······················· 1
1.1.2 VSTO开发语言 ····························· 2
1.1.3 VSTO开发环境配置 ······················· 3
1.1.4 Visual Studio开发环境 ·····················
4
1.1.5 Visual Studio版本沿革 ·····················
4
1.1.6 Visual Studio的安装 ························ 4
1.2 创建个C#应用程序 ················· 5
1.2.1 控制台应用程序 ···························· 5
1.2.2 Windows窗体应用程序 ··················· 9
1.2.3 生成可执行文件 ···························11
1.3 认识Visual Studio开发环境·············11
1.3.1 【文件】菜单 ······························12
1.3.2 【视图】菜单 ······························12
1.3.3 【项目】菜单 ······························12
1.3.4 菜单栏和工具栏的自定义 ···············13
1.3.5 Visual Studio选项 ··························14
1.4 Visual Studio项目组织结构 ·············14
1.4.1 解决方案 ····································14
1.4.2 项目 ··········································17
1.4.3 类模块 ·······································18
1.4.4 引用管理 ····································18
1.5 使用帮助系统 ·····························19
1.5.1 设置帮助查看方式 ························19
1.5.2 下载和安装Help Viewer ··················19
1.5.3 管理帮助内容 ······························19
本章要点回顾····································21
第2章 C#语法基础
··················· 22
2.1 变量的声明和赋值 ······················22
2.1.1 常用的数据类型 ···························22
2.1.2 赋值运算符 ·································23
2.1.3 变量的作用范围 ···························23
2.2 字符与字符串处理 ·······················24
2.2.1 字符变量 ····································24
2.2.2 字符串变量 ·································25
2.2.3 转义字符 ····································26
2.2.4 字符串连接 ·································27
2.2.5 子字符串 ····································27
2.2.6 格式化字符串 ······························28
2.2.7 字符串的替换 ······························28
2.2.8 字符串与数组 ······························28
2.3 逻辑运算 ···································29
2.3.1 布尔型变量 ·································29
2.3.2 比较运算符 ·································30
2.3.3 多条件的与或非运算 ·····················30
2.4 不同类型的强制转换 ····················31
2.4.1 ToString
·····································31
2.4.2 Parse
·········································31
2.4.3 Convert
······································32
2.5 使用数组 ···································33
2.5.1 数组的声明和初始化 ·····················33
2.5.2 一维数组 ····································33
2.5.3 数组元素的遍历 ···························34
2.5.4 二维数组 ····································35
2.6 条件选择语句 ·····························37
2.6.1 三元运算符 ·································37
2.6.2 if语句 ········································38
2.6.3 switch语句 ··································39
2.7 循环语句 ···································40
2.7.1 while循环 ···································40
2.7.2 do循环 ·······································41
2.7.3 for循环 ······································42
2.7.4 foreach循环·································43
2.8 流程控制语句 ·····························43
2.8.1 break语句 ···································43
2.8.2 continue语句 ·······························44
2.8.3 goto语句 ····································44
2.8.4 return语句 ···································45
2.9 输出对话框(MessageBox) ··········46
2.9.1 MessageBox语法 ··························46
2.9.2 自定义对话框的按钮 ·····················47
2.9.3 自定义对话框的图标 ·····················48
2.9.4 自定义对话框默认按钮 ··················48
2.9.5 处理对话框的用户响应 ··················48
2.10 输入对话框(InputBox)
·············49
2.11 过程与函数 ······························50
2.11.1 过程与函数的定义 ······················50
2.11.2 过程与函数的调用 ······················51
2.12 类的创建和使用 ························52
2.12.1 非静态类 ··································52
2.12.2 静态类 ·····································54
2.13 using指令 ·································55
2.14 错误处理 ·································55
本章要点回顾····································56
第3章 C#进阶技术
···················57
3.1 文件与文件夹操作 ·······················57
3.1.1 System.IO命名空间 ·······················57
3.1.2 文件与文件夹处理实例 ··················58
3.2 文本文件的读写 ··························59
3.3 数据库操作 ································60
3.4 使用资源文件 ·····························61
3.4.1 添加资源文件 ······························62
3.4.2 资源文件中的字符串 ·····················62
3.4.3 资源文件中的图像 ························63
3.5 使用正则表达式 ··························65
3.5.1 创建Regex对象 ····························65
3.5.2 元字符 ·······································65
3.5.3 正则表达式选项 ···························66
3.5.4 正则表达式方法 ···························67
3.5.5 正则表达式测试器 ························71
3.6 使用字典 ···································72
3.6.1 字典对象的创建 ···························72
3.6.2 根据键检索值 ······························73
3.6.3 遍历所有键名 ······························74
3.6.4 遍历所有值 ·································74
3.6.5 去除重复 ····································74
3.7 窗体设计技术 ·····························76
3.7.1 窗体的显示 ·································76
3.7.2 窗体的卸载 ·································77
3.7.3 窗体与控件的事件 ························78
3.7.4 使用窗体菜单 ······························82
3.7.5 使用工具栏 ·································85
3.7.6 使用右键菜单 ······························87
3.7.7 使用状态栏 ·································88
3.7.8 使用文件选择对话框 ·····················90
3.7.9 运行期间动态增删控件 ··················91
3.8 使用Windows API 函数 ··················94
3.8.1 窗口类名和句柄 ···························95
3.8.2
使用Spy ··································98
3.8.3
使用UseAPI ······························ 100
3.8.4 获取光标位置 ···························· 101
本章要点回顾·································· 101
第4章 C#操作Excel对象·········· 102
4.1
Excel对象模型概述 ····················
102
4.1.1 Application对象 ·························· 103
4.1.2 Workbook 对象 ··························· 104
4.1.3 Worksheet 对象 ··························· 104
4.1.4 Range对象 ································ 105
4.1.5 Window 对象 ······························ 105
4.2
创建可以访问Excel对象的C#窗体
应用程序
································· 105
4.2.1 添加Excel 2010对象引用 ·············· 105
4.2.2 添加Office 2010对象引用 ·············· 105
4.3 操作Application对象 ···················
107
4.3.1 获取正在运行的Excel对象 ············ 107
4.3.2 创建新的Excel对象 ·····················
109
4.3.3 Application对象常用属性 ·············· 109
4.3.4 Application对象常用方法 ·············· 110
4.3.5 Application对象常用事件 ·············· 110
4.3.6 Application重要集合对象 ·············· 111
4.4 操作Workbook 对象···················· 112
4.4.1 Workbook 对象常用属性··············· 112
4.4.2 Workbook 对象常用方法··············· 113
4.4.3 Workbook 对象常用事件··············· 114
4.4.4 Workbook 重要集合对象··············· 114
4.5 操作Worksheet 对象 ····················
115
4.5.1 Worksheet 对象常用属性 ··············· 115
4.5.2 Worksheet 对象常用方法 ··············· 116
4.5.3 Worksheet 对象常用事件 ··············· 117
4.6 操作Range对象 ························· 117
4.6.1 Range对象常用属性···················· 117
4.6.2 Range对象常用方法···················· 118
4.6.3 Range对象的遍历 ······················· 119
4.6.4 二维数组与Range数据交换··········· 120
4.6.5 一维数组与Range数据交换··········· 121
4.7 操作Commandbar对象 ················ 121
4.8 操作VBE工程 ·························· 123
4.8.1 引用VBIDE类型库 ······················ 123
4.8.2 允许对VBA工程访问 ··················
123
4.8.3 操作VBE各级对象 ······················ 125
4.9
创建Excel自定义函数
················· 125
4.9.1
使用C#创建类库
························ 126
4.9.2
工作表中使用C#开发的自定义
公式
········································ 129
4.9.3
VBA中调用C#开发的自定义公式 ··· 131
4.9.4
C#中调用C#开发的自定义公式 ······ 131
4.9.5 客户机使用C#制作的自定义函数 ·······132
本章要点回顾·································· 133
第5章创建Office外接程序······· 134
5.1
Office COM加载项简介 ··············· 134
5.2
认识Office COM加载项管理
对话框
···································· 134
5.3 创建个Office外接程序项目 ····135
5.4 ThisAddin的启动事件和卸载事件 ··136
本章要点回顾··································137
第6章
自定义Office功能区
·······138
6.1 CustomUI概述 ··························138
6.1.1 CustomUI的意义 ························140
6.1.2 CustomUI的作用范围 ··················140
6.1.3 手工定制Office界面 ····················140
6.2 CustomUI与XML ·······················141
6.2.1 XML语法规则 ···························141
6.2.2 描述Office界面的XML ·················142
6.2.3 使用Ribbon XML Editor ···············148
6.3 CustomUI元素详解 ····················149
6.3.1 选项卡(tab)元素 ·····················150
6.3.2 组(group)元素 ························151
6.3.3 控件(control)元素 ···················151
6.4 VSTO中使用功能区可视化
设计器 ····································154
6.4.1 为按钮指定回调过程 ···················156
6.4.2 Group中加入DialogBoxLauncher ·····157
6.5 使用XML进行CustomUI定制 ········159
本章要点回顾··································162
第7章
自定义任务窗格 ············163
7.1 任务窗格行为控制 ·····················163
7.2 VSTO外接程序项目中添加任务
窗格 ·······································164
7.2.1 创建Excel 2010外接程序 ··············165
7.2.2 添加用户控件 ····························165
7.2.3 静态类中声明任务窗格对象 ··········166
7.2.4 创建并显示任务窗格 ···················167
7.3 功能区与任务窗格的交互控制 ······169
7.3.1 利用功能区切换按钮控制任务窗格的
显示隐藏 ··································169
7.3.2 处理自定义任务窗格事件 ·············172
7.3.3 完全卸载任务窗格 ······················173
本章要点回顾··································173
第8章
自定义工具栏 ···············174
8.1 Office工具栏对象简述 ················174
8.1.1 Commandbar对象 ·······················174
8.1.2 CommandbarControl对象 ··············175
8.1.3 自定义工具栏的作用和意义 ··········176
8.2 VSTO实现自定义工具栏 ·············176
8.2.1 创建自定义工具栏 ······················176
8.2.2 处理工具栏按钮的回调 ················178
8.2.3 修改右键菜单 ····························179
8.2.4 卸载外接程序时清除自定义 ··········180
本章要点回顾··································181
第9章 VSTO外接程序的部署分发
···182
9.1 客户机搭建VSTO运行环境 ··········182
9.2 VSTO外接程序的简单安装 ··········183
9.3 使用Advanced Installer ················184
9.3.1 创建aip安装包工程 ·····················184
9.3.2 客户机运行安装包 ······················193
本章要点回顾··································194
第10章 VSTO开发Office文档
···195
10.1 文档自定义项编程概述 ·············195
10.2 文档自定义项允许添加的界面
元素 ·····································195
10.3 创建Office文档项目 ··················196
10.3.1 文档上添加C#控件 ····················198
10.3.2 文档项目的启动事件过程 ···········198
10.4 文档操作窗格概述 ···················199
10.5 文档操作窗格综合实例 ·············200
10.5.1 添加用户控件到文档窗格 ···········202
10.5.2 添加多个相同控件到文档窗格 ·····204
10.5.3 使用代码创建窗体控件并添加到
文档操作窗格 ··························205
10.5.4 定制功能区按钮控制文档操作
窗格 ······································206
10.6 文档自定义项的部署分发 ··········210
本章要点回顾··································211
第11章 VSTO开发资源大全
·····212
11.1 Office 2003以下版本工具栏和控件的
自定义 ··································212
11.1.1 OfficeCommandbarDesigner
··········212
11.1.2 OfficeCommandbarViewer
············213
11.1.3 FaceIDViewer
···························213
11.2 Office 2007以上版本功能区的
自定义 ··································215
11.2.1 Office2010ControlIDs
·················215
11.2.2 imageMso7345
··························216
11.2.3 OfficeCustomUIEditor
·················217
11.2.4 Ribbon XML Editor
····················217
11.2.5 Ribbon回调函数大全 ··················217
11.3 编程环境辅助工具 ···················218
11.3.1 VBE2014
································219
11.3.2 VisualStudioAddin2016
···············220
第12章 C#与VB/VBA语言的差异
对比··························222
12.1 变量必须声明 ·························222
12.2 严格的类型匹配 ······················222
12.3 项目的自动保存 ······················222
12.4 严格区分大小写 ······················223
12.5 语句结束必须加分号 ················223
12.6 语句块 ··································223
12.7 调用其他函数圆括号不能少 ·······224
12.8 数组的下标为0 ························224
12.9 数组或集合对象的索引使用
方括号 ··································225
VSTO 开发入门教程阶段:熟悉Visual Studio编程环境? 理解VSTO的概念? 安装Visual Studio? 熟悉解决方案和项目文件夹第二阶段:熟悉C#语言? 创建C#窗体应用程序、窗体与常用控件的使用? C#语法基础(变量、控制语句、不同数据类型的转换等)? 程序代码调试、错误处理? 使用类第三阶段:C#操作和控制Excel对象? 熟悉Excel对象模型,Excel对象的常用属性、方法和事件? 加强从VBA代码向C#代码迁移的能力第四阶段:界面设计部分? 定制功能区:使用功能区设计器或使用XML代码,理解Custom UI机制? 任务窗格:任务窗格中控件和用户控件的添加? 创建文档自定义项,使用文档操作窗格? 自定义工具栏第五阶段:VSTO项目分发与安装程序的制作? 使用Advanced Installer其他知识点? 使用C#制作Excel自定义函数(UDF)? 创建Word、PPT等组件的VSTO项目VSTO课程学习路线图本书内容本书内容以VSTO学习路线图为依据编排而成,全书共分12章。第1章:VSTO入门概述本书介绍的是一项程序开发技术,因此首先要让读者安装必要的程序语言和开发环境。然后讲述VSTO开发的意义和任务,以及创建和调试C#解决方案的方法与步骤。第2章:C#语法基础 III本书以C#为开发语言,因此读者需要掌握一定程度的C#语法基础。该章介绍了变量的声明和赋值、流程控制与类的使用。第3章:C#进阶技术该章讲述了C#窗体与控件的相关技术,以及像正则表达式、字典等高级对象的用法,目的是让读者在开发过程中,能够熟练应用这些高级对象去处理实际问题。第4章:C#操作Excel对象前面3章讲述的是纯粹的C#语言,而从这一章开始,讲述如何使用C#操作和控制Office对象,该章以Excel为例,介绍了Excel的应用程序、工作簿、工作表、单元格区域等对象的成员。第5章:创建Office外接程序VSTO开发的目的旨在创建Office外接程序(即COM加载项)。该章介绍了COM加载项的工作原理和开发基本步骤。第6章:自定义Office功能区,第7章:自定义任务窗格第6章和第7章分别介绍了VSTO开发的重点,一般来说,创建一个Office外接程序,界面定制是非常必要的,为此本书在这两章里详尽地介绍了功能区的自定义技术和自定义窗格的设计方法。第8章:自定义工具栏Office工具栏是Office组件中很重要的一个界面对象,为此本书通过典型的实例,讲述了工具栏和控件的自定义方法。第9章:VSTO外接程序的部署分发VSTO开发的成品,一般需要能够在其他计算机上正常使用,为此,该章介绍了使用Advanced Installer软件来创建VSTO项目的安装程序。第10章:VSTO开发Office文档文档自定义开发是VSTO另一类型的项目。该项目允许自定义文档,可以向文档中加入C#控件,以及创建和控制文档窗格。第11章:VSTO开发资源大全“工欲善其事,必先利其器”,为了能够驾轻就熟地进行VSTO开发,还需要使用其他一些工具的辅助,为此,该章介绍了典型工具的安装和使用技巧。第12章:C#与VB/VBA语言的差异对比考虑到很多读者是从VBA转过来的,对VBA的语法和对象模型更为熟悉,为了能够帮助读者更快地从VBA转入VSTO,该章列出了两种语言典型的语法差异。
VSTO 开发入门教程本书特点本书是目前市面上稀缺而Office开发人员急需的、Office和C#技巧完美融合的经典书籍,为了让读者快速了解和熟悉VSTO,本书第2~4章的C#代码都配备了对应的VBA代码,可以让之前从事VBA开发的读者迅速学会VSTO开发。同时本书配套资源中包括本书涉及的所有项目的源文件,以便读者加以验证和核对。另外,本书配套资源中还有与VSTO开发相关的全部有声视频教程。本书配套资源内容说明本书配套资源包括VSTO开发入门视频教程、本书所有示例程序、VSTO开发资源大全三大部分内容。关于本书配套资源,读者可访问http://vba.mahoupao.net/forum.php?mod=viewthread&tid=2407&fromuid=1进行下载。大分类文件名对应章节或描述VSTO开发入门视频教程VSTO概述.wmv 第1章C#语法基础.wmv 第2章类的创建和使用.wmv 2.12节窗体和控件的设计技术.wmv 3.7节C#操作Excel对象.wmv 第4章创建Office外接程序.wmv 第5章使用Ribbon设计器自定义Office功能区.wmv 6.4节使用XML自定义Office功能区.wmv 6.5节自定义任务窗格的设计.wmv 第7章VSTO外接程序的打包.wmv 第9章VSTO开发Office文档-文档操作窗格.wmv 第10章示例程序ConsoleApplication20160629 1.2.1节ExcelAddIn20160514 6.4节ExcelAddIn20160515 6.5节ExcelAddIn20160516 7.2节ExcelAddIn20160517 8.2.1节ExcelWorkbook20160519 10.3节Solution20160705 1.4节UDF20160521 4.9.1节VSTOBOOK-C# 第2章VSTOBOOK-VB 第2章WindowsFormsApplication20160522 4.2节WindowsFormsApplication20160523 3.4节
大分类文件名对应章节或描述示例程序WindowsFormsApplication20160524 3.5.4节WindowsFormsApplication20160525 3.6节WindowsFormsApplication20160526 3.7节WindowsFormsApplication20160527 3.7.9节WindowsFormsApplication20160528 3.8节WindowsFormsApplication20160606 2.2节WindowsFormsApplication20160625 2.12节WindowsFormsApplication20160629 1.2.2节VSTO开发资源大全OfficeCommandbarDesigner20160709.rar11.1节OfficeCommandbarViewer20160709.rarFaceIDs_V2_20160709.xlsFaceIDs_V2_20160709.docOffice2010ControlIDs.rar11.2节imageMso7345.xlsmOfficeCustomUIEditorSetup.msiRibbonXMLEditor20160709.rarribbon回调函数大全.xlsmUseAPI.rar 3.8节VBE2014_Setup_2016070911.3节VisualStudioAddin2016Setup.exe读者对象● 职场办公人员● 理工科类大学生、研究生● 编程爱好者● 培训机构的老师和学员本书约定书中述及的多级菜单和工具栏的图示中,鼠标单击的各级菜单或命令均放在中文方括号之中,各级之间以斜杠隔开。例如【文件/打开】表示连续单击了“文件”菜单的“打续表VSTO 开发入门教程开”子菜单。书中所有的VBA和C#代码段,代码左侧均有行号,这些行号只是为了便于讲解,并不属于代码部分。读者服务为了方便本书内容答疑,读者朋友可加入VBA/VSTO开发QQ群:61840693,也可以在VBA/VSTO论坛(http://vba.mahoupao.net/forum.php)发帖,还可以直接给作者发Email:[email protected]。无论哪一种方式,作者将竭诚为您服务。如果要进一步学习Office、VBA、VSTO等学科的视频课程,读者可在51CTO学院搜索作者主讲的相关课程:http://edu.51cto.com/user/user_id-6673733.html。致谢感谢刘爱珍、儒道佛潘淳、西西老师、张杰、闻启学等朋友以及兄长刘永和在本书编写过程中给予的无私帮助和鼓励。本书在出版过程中,得到了清华大学出版社策划编辑秦健先生的大力支持和配合,在此表示衷心感谢。另外,本书所有的编审、发行人员为本书的出版和发行付出了辛勤劳动,在此一并致谢。特别说明本书编写时所用的VSTO开发环境如下:● 操作系统:Windows 7(32bit)● Office:Office 2010完整版● Visual Studio:Visual Studio 2012● 开发语言:C#读者可以根据自身条件适当调整。另外,本书涉及的所有VSTO示例,均以Excel 2010为开发对象,对于其他Office组件的开发,过程非常类似,读者可以在Excel开发的基础上自行探索。致读者微软Office套件称得上是全世界成功的办公软件,拥有非常多的用户。它之所以受到人们的青睐,有多方面的原因,但是以下几点是有目共睹的:一是功能完善而且强大;二是容易操作,用户容易学会;三是具有强大的编程开发功能。 VII随着计算机的发展,以往的手工操作办公软件已经不能满足现代办公的需要,因此,VBA以及VSTO开发和应用技术应运而生。本书在编写过程中,受到了众多Office开发人员的关注,他们殷切希望本书尽早出版。除了刘永富之外,参与本书编写的人员还有章晓琳、马成林、钟卓成、李四桂、何明、段留柱、高大伟、肖云、谭信章、戴海东、朱辉、徐鹏、祝磊、管洪洋、刘爱珍、王继成、汪龙、林兴龙、梁加成等。在编写过程中难免会有漏洞,欢迎读者通过清华大学出版社网站(www.tup.com.cn)与我们联系,帮助我们改正提高。刘永富2016年7月于北京
评论
还没有评论。