VSTO開發入門教程

VSTO開發入門教程

《VSTO開發入門教程》是2017年1月清華大學出版社出版的圖書,作者是劉永富。

基本介紹

  • 中文名:VSTO開發入門教程
  • 作者:劉永富
  • 出版社:清華大學出版社
  • 出版時間:2017年1月
  • 定價:45 元
  • ISBN:9787302453710
內容簡介,圖書目錄,

內容簡介

本書從初學者角度出發,詳細介紹了使用C#語言進行VSTO開發需要掌握的知識。全書分為12章,內容包括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

相關詞條

熱門詞條

聯絡我們