
VSTO学习笔记一
发布日期:2021-05-14 04:36:43
浏览次数:16
分类:博客文章
本文共 6704 字,大约阅读时间需要 22 分钟。
1������������������������Excel���
View Code
private void Sheet1_Startup( object sender, System.EventArgs e) { #region the first method Application.ScreenUpdating = false ; Application.Workbooks.Open( @" C:\regist.log " ,System.Type.Missing, false ,System.Type.Missing,System.Type.Missing,System.Type.Missing,System.Type.Missing,System.Type.Missing, " , " , true ,System.Type.Missing,System.Type.Missing, true ,System.Type.Missing,System.Type.Missing); Application.ScreenUpdating = true ; #endregion ���
2������������������������Excel���
View Code
private void Sheet1_Startup( object sender, System.EventArgs e) { #region the second method this .Application.Workbooks.OpenText( " http://www.baidu.com " , Excel.XlPlatform.xlMacintosh, 3 , Excel.XlTextParsingType.xlDelimited, Excel.XlTextQualifier.xlTextQualifierNone, missing, missing, missing, false , missing, missing, missing, missing, missing, missing, missing, missing, missing); #endregion }
3���������DataSet���������Excel���
View Code
private void Sheet1_Startup( object sender, System.EventArgs e) { #region the third method:load the dataset into the worksheet DataSet ds = GetDataSet(); int count = 1 ; foreach (DataRow dr in ds.Tables[ 0 ].Rows) { Excel.Range rng = this .Application.get_Range( " A " + count ++ ,missing); rng.Value2 = dr.ItemArray; } #endregion ���
4���������Excel���sheet
View Code
private void Sheet1_Startup( object sender, System.EventArgs e) { #region the forth method:delete the worksheet Application.DisplayAlerts = false ; ((Excel.Worksheet) this .Application.ActiveWorkbook.Sheets[ 2 ]).Delete(); Application.DisplayAlerts = true ; Application.Quit(); #endregion }
5���������Excel������������
View Code
private void Sheet1_Startup( object sender, System.EventArgs e) { #region the fifth method:the excel named ranges Microsoft.Office.Tools.Excel.NamedRange namedRange1 = Controls.AddNamedRange( this .Range[ " A1 " , " A10 " ], " namedRange1 " ); Microsoft.Office.Tools.Excel.NamedRange namedRange2 = Controls.AddNamedRange( this .Range[ " A1 " ,missing], " namedRange2 " ); namedRange1.Merge( false ); namedRange2.Merge( false ); namedRange1.BorderAround(missing, Excel.XlBorderWeight.xlHairline, Excel.XlColorIndex.xlColorIndexAutomatic, missing); namedRange1.AutoFormat(Excel.XlRangeAutoFormat.xlRangeAutoFormat3DEffects1, true , false , true , false , true , true ); #endregion }
6���������������������
View Code
private void Sheet1_Startup( object sender, System.EventArgs e) { #region this sixth method:cell manipulation Excel.Range rng = Globals.Sheet1.Range[ " B3 " , " B3 " ] as Excel.Range; rng.Value2 = " 123456 " ; rng.NumberFormat = " $#,###.0 " ; rng = rng.Cells[ 3 , 3 ] as Excel.Range; rng.Value2 = " new " ; #endregion }
7������������������
View Code
private void Sheet1_Startup( object sender, System.EventArgs e) { #region the seventh method:working with unions Excel.Range rngA = Globals.Sheet1.Range[ " a2 " , " B3 " ] as Excel.Range; rngA.Value2 = " Mortgage " ; Excel.Range rngB = Globals.Sheet1.Range[ " a5 " , " B6 " ] as Excel.Range; rngB.Value2 = " Interest " ; Excel.Range unionRange = Application.Union(rngA,rngB,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing,missing) as Excel.Range; unionRange.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red); #endregion }
8���������������
View Code
private void Sheet1_Startup( object sender, System.EventArgs e) { #region the eighth method:workbook password protection string password = this .Password; this .Protect(password, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); this .Unprotect(password); #endregion }
9������������������������
View Code
private void Sheet1_Startup( object sender, System.EventArgs e) { #region the ninth method:responding to events Microsoft.Office.Tools.Excel.NamedRange namedRange1 = Globals.Sheet1.Controls.AddNamedRange(Globals.Sheet1.Range[ " A1 " ,missing], " NamedRange " ); namedRange1.Change += new Microsoft.Office.Interop.Excel.DocEvents_ChangeEventHandler(namedRange1_Change); #endregion } private void namedRange1_Change(Microsoft.Office.Interop.Excel.Range target) { if ( ! this .Application.CheckSpelling(( string )target.Value2, null , true )) { MessageBox.Show( " ��������������� " ); } }
���������������������Wrox.Professional.VSTO.2005.Visual.Studio.2005.Tools.for.Office.May.2006.pdf
发表评论
最新留言
路过按个爪印,很不错,赞一个!
[***.219.124.196]2025年04月08日 21时11分55秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
【.net+jquery】绘制自定义表单(含源码)
2021-05-16
JavaScript--onblur失去焦点-触发事件
2021-05-16
elasticsearch-5.0.1启动方法
2021-05-16
统计建模与R
2021-05-16
B1005 继续(3n+1)猜想
2021-05-16
B1077 互评成绩计算(python)
2021-05-16
【存储】如何理解Cookie?
2021-05-16
【JS面试题】什么是作用域?什么是自由变量?
2021-05-16
【React基础】jsx的基础使用
2021-05-16
【ES6】何为动态计算属性名?
2021-05-16
【JS基础】常用的数组方法和字符串方法
2021-05-16
【Koa】简单聊聊 ORM 基本概念、ORM应用
2021-05-16
【CSS基础】关于height:100%和height:100vh的区别
2021-05-16
【前端面试】到底我的简历该怎么写?才有机会被邀请面试?【看此文章即可!!!】
2021-05-16
【前端面试】点击一个input依次触发的事件
2021-05-16
【TS基础】初学之 Interface 接口定义
2021-05-16